In computer science, Deadlock is a naughty boy aroused by compete for resources. Even now,

    there isn't a valid method to deal with it. This is amazing. You know, we have many excellent

    scientists,  not all of issues can fight with us so many years. Fortunately, we can still do something

    by sacrifice some system efficiency. Those methods can be divided into three categories:

    Preventation, avoidance, and detection. Let us examine them at the following text.

1.Deadlock Preventation

Deadlock preventation is aim to solve this problem radically. From some point of view, the

    deadlock is weak. It must satisfy some conditions:

            a). the use of resource is mutual exclusive.

            b). No preemptive.

            c). some processes hold the resource that another process waiting.

            d). circle waiting.  i.e: P1 wait P2 release a special resource, P2 wait P3, and P3 wait P1.

Those are necessary conditions. If only we can break one of them, we can win this war. That

    naughty boy will never occur again. The condition (a) is hard to break since we need mutual

    exclusion to ensure the safe of data access, this is reasonable. Now, let us see the remainder.

            condition b -- request all required resources at one time. If the process can't get all of them,

                                then release all of them, and try again.

            condition c -- If we can rob a resource from the process and restore it easily. This will be

                                good choice.

            condition d -- by some ingenious arrangement , we can overcome a circle waiting.

2.Deadlock Aviodance

Deadlock Avoidance is aim to dynamically avoid a deadlock. From some point of view, this is

    possible. But there are some restriction in this method. Now, the problem is how can we ensure

    a action is safe when a process want to allocate some resources. can we ?

we can. As we all know,one of the reason that aroused a deadlock is that the required resource

    has been exceed the exist resources. So we can know whether a action lead to a deadlock

    potentially by this rule. First at all, we need save some information about the status of resouces.

    The following item is necessary. How many resources in this system? How many resouces is

    available? the list of processes which need to those resources? The list of resources which has

    been allocated by processes?

There must be have many solutions. A common method to record those information as following:

            A vector for available resources. i.e:

                    [1,2,3]

            that means resource R1 have 1 unit in current system status; In a similar way, R2 have 2 units,

            and R3 have 3 units.

A vector for the total amount of resources.

                    [2,3,4]

            that means the total of resources R1 is 2 units, R2 is 3, and R3 is 4.

A matrix for the amount of allocated resources.

                         R1   R2   R3

                   P1   1    0    0

                   P2   0    1    1

                   P3   0    0    0

             That means P1 has allocated a R1, P2 has been allocate a R2 and R3, and P3 has

             allocated nothing.

A matrix for the amount of resources what required by process. i.e:

                         R1   R2   R3

                   P1   1     1     1

                   P2   1     1     1

                   P3   1     0     1

        That means, if process P1 want to complete it's work, it need one R1, one R2 and one R3.

Based on our convention above, There are some strategies.

            solution 1:

                    Don't start a process if it's demand may lead to a deadlock.This is conservative strategy.

                we always assume the worst situation. In other words, every process allocate all required

                resources when it start. So if we want to start a process X,we need to know whether this

                condition can be satisfied.(if the process 1~n has running)

                        C[1][i] + C[2][i] +.... C[n][i] + C[x][i] < R[i]  (for all of i)

Athough it is work, but there are some problems here because not all of resources are

                required all the time. Some of them may be used rarely.

solution 2:

                    if all of processes are independent, except for the use of some common resources.

                we could use a more effective method--nest. In this strategy, we grant the request of a

                process only if this process could be completed by current available resources .Think

                about this situation:

   

                    At the beginning. The status of system is,

                            V(available)   =  (5);

                            R(Resources)  =  (10);

                            A(Allocated)   =  {  {2},

                                                        {3},

                                                        {0} };

                            C(Claim)    = { {8},

                                                  {5},

                                                  {5} };

                    Based on this status, we could get

                            C - A = { {6},

                                          {2},

                                          {5} };

we can know P1 can't working because they need 6 uint of resouces and that is out

                of the system's league.In contrast, P2  and P3 is good. In this situation, what should

                we do?

                    The answer is refuse the request from P1, because P1 maybe lead to a deadlock.

Based on our analysis above,If we get a request from P2 about request 1 unit of

                resource, that request should be granted. Then status will become

                            V(available)  =  (4);

                            R(Resources) = (10);

                            A(Allocated)  = { {2},

                                                     {4},

                                                     {0} };

                            C(Claim)    = { {8},

                                                  {5},

                                                  {5} };

                and

                            C - A = { {6},

                                          {1},

                                          {5} };

                    In this status, P1 and P3 is not a nice guy. we should refuse both them....

                    This strategy was called Banker's Algorithm. As we can see, if all of processes is independent,

                it will work more better than the above one.

3. Deadlock Detection

The method above is working by add some restriction to the process. But Deadlock Detection

    is different. It didn't work untill a deadlock occur. In this strategy, the system will grant all of

    request , but will detect whether a deadlock has occur. If a deadlock has been found, the system

    will deal with it by some method. There are two problems here:

 

    Q:   How can we detect a deadlock?

    A:   Actually, this is easy. Recall the banker's algorithm, in there we avoid a deadlock by ensure

          every request is come from a safe process. If we reverse the progress of the banker's

          algorithm, we can get what we want.

a). detect all running processes whether there is a safe process in system. If success,

                go to next step, Or ,terminate this detection.

            b). find a safe process which can working by current available resources.

            c). Assume this process has been completed and release all of resources what it allocated.

            d). return to step a.

when we terminate this detection, the remainder process,which is unlabeled, maybe involve

          a deadlock.

Q:   How can we recover it?

    A:   Actually,there isn't a valid method to do this. That is awful.Fortunately,some method,which

          are not so valid,can working .For example:1).we could set some restore points.But the problem

          is where should be the point;2).Re-assign resource; and so on. we can choice them based on

          where it is.

Deadlock preventation, Deadlock avoidance, and Deadlock detection is aim to deal with a

    deadlock from the point of view of system. But it is the responsibility of the programmer also.

system strategies of Resources Deadlock的更多相关文章

  1. 在运行时切换 WinForm 程序的界面语言 System.ComponentModel.ComponentResourceManager .ApplyResources

    Download the code for this article: WinForm-Multilanguages-2.rar (11 KB). 方法二: 下面介绍一种只需对现有代码做较小改动的方法 ...

  2. 异常:System.InvalidOperationException: This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms FIPS信息标准限值了MD5加密

    最近做的winform项目中,有个功能使用了MD5 加密,本地测试是没有问题的,但是上线后有些用户反馈说提示如下错误 一.问题描述 中文版错误截图 英语版错误截图 具体错误信息: 有关调用实时(JIT ...

  3. The Qt Resource System

    The Qt Resource System The Qt resource system is a platform-independent mechanism for storing binary ...

  4. “System.Runtime.InteropServices.COMException (0x80070422): 无法启动服务”解决方法

    应用程序中发生了无法处理的异常.如果单击“退出”,应用程序将立即关闭.无法启动服务,原因可能是已被禁用或其相关联设备没有启动.(异常来自HRESULT:0X80070422).点击详细内容:有关调用实 ...

  5. 在Magento System Configuration页面添加配置项

    以 Jp_Coupon 模块为例: 目标: 在 System configuration 页面添加一个 JP tab, 在JP中添加 Coupon section, 然后给 Coupon sectio ...

  6. Method, apparatus and system for acquiring a global promotion facility utilizing a data-less transaction

    A data processing system includes a global promotion facility and a plurality of processors coupled ...

  7. 转 Oracle 12c: Managing Resources

    http://www.oracle-class.com/?p=3058 1. Introduction: Oracle database 12c comes with several Resource ...

  8. Method and system for providing security policy for linux-based security operating system

    A system for providing security policy for a Linux-based security operating system, which includes a ...

  9. Single-stack real-time operating system for embedded systems

    A real time operating system (RTOS) for embedded controllers having limited memory includes a contin ...

随机推荐

  1. SE 2014年5月27日

    R1模拟总部,R2 与R3模拟分部 如图配置 要求使用 GRE over IPSec VPN 主模式,启用动态路由协议rip使得总部与两分部内网可相互通讯,但要求分部用户数据流不允许互通! 步骤: 1 ...

  2. SE 2014年4月22日(一)

    实验 练习: 如图配置: 两自治系统 AS 100  和 AS 200 AS 100 是由两私有自治系统 (AS 65001 和 AS 65002)构成 要求配置BGP联盟 使得 R3 R4 R5 下 ...

  3. AJAX基础知识点学�

    1.AJAX(Asynchronous JavaScript and XML)即,异步JavaScript和XML 2.同步/异步差别 同步: ①每次进行整个页面的刷新 ②同步的链接在同一时间仅仅能有 ...

  4. ubuntu软件中心崩溃

    网上找了下别人的解决方法(本人測试成功解决此问题): 提示说是lists出错 我的正是这样的情况 使用例如以下命令能够修复: 1.删除lists sudo rm /var/lib/apt/lists/ ...

  5. macbook连接linuxserver后不显示matlab桌面[问题]

    macbook 登录远程linuxserver.Macbook今天,系统版本号10.9.4.这是更新,打开matlab当提醒x11不存在.一个接着安装Xquarz2.7.6. matlab它可以在本地 ...

  6. 获取编译学习笔记 (六)—— si、di,双环

    疯狂暑期学习  汇编入门学习笔记 (六)-- si.di,双重循环 參考: <汇编语言> 王爽 第7章 1. and和or指令,与[bx+idata] and和or.就不多说了. [bx+ ...

  7. 第三章 AOP 编程选择

    Spring为我们开发者提供了多种AOP的编程方式.我们该如何选择呢? 如果项目采用的是JDK5.0以上版本,我们可以选择@AspectJ的方式.这是第一选择. http://blog.csdn.ne ...

  8. 分享几个免费的开源邮件server软件

    因为企业的须要,我们非常可能须要架设一个邮件server,微软的Exchange太复杂?GOOGLE出来的又收费!头大了吧,OK,贾芸斐在这里给大家分享推荐几个免费的开源的邮件server软件.希望你 ...

  9. GPS 偏移校正(WGS-84) 至(GCJ-02) java版本号以实现

    public class EvilTransform { final static double pi = 3.14159265358979324; // // // a = 6378245.0, 1 ...

  10. HTML5 CSS3 诱人的实例 : 网页载入进度条的实现,下载进度条等

    今天给大家带来一个比較炫的进度条,进度条在一耗时操作上给用户一个比較好的体验,不会让用户认为在盲目等待,对于没有进度条的长时间等待,用户会任务死机了,毫不犹豫的关掉应用:一般用于下载任务,删除大量任务 ...