




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、7.2nto develop a description of deadlocks, which prevent sets of concurrent processes from completing their tasksnto present a number of different methods for preventing or avoiding deadlocks in a computer system.7.3nthe deadlock problemnsystem modelndeadlock characterizationnmethods for handling de
2、adlocksndeadlock preventionndeadlock avoidancendeadlock detection nrecovery from deadlock 7.4na set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set.nexample lsystem has 2 disk drives.lp1 and p2 each hold one disk drive and each needs
3、another one.nexample lsemaphores a and b, initialized to 1 p0 p1wait (a);wait(b)wait (b);wait(a)7.5ntraffic only in one direction.neach section of a bridge can be viewed as a resource.nif a deadlock occurs, it can be resolved if one car backs up (preempt resources and rollback).nseveral cars may hav
4、e to be backed up if a deadlock occurs.nstarvation is possible.7.6nresource types r1, r2, . . ., rmcpu cycles, memory space, i/o devicesneach resource type ri has wi instances.neach process utilizes a resource as follows:lrequest luse lrelease7.7nmutual exclusion: only one process at a time can use
5、a resource.nhold and wait: a process holding at least one resource is waiting to acquire additional resources held by other processes.nno preemption: a resource can be released only voluntarily by the process holding it, after that process has completed its task.ncircular wait: there exists a set p0
6、, p1, , p0 of waiting processes such that p0 is waiting for a resource that is held by p1, p1 is waiting for a resource that is held by p2, , pn1 is waiting for a resource that is held by pn, and p0 is waiting for a resource that is held by p0.deadlock can arise if four conditions hold simultaneousl
7、y.7.8nv is partitioned into two types:lp = p1, p2, , pn, the set consisting of all the processes in the system.lr = r1, r2, , rm, the set consisting of all resource types in the system.nrequest edge directed edge p1 rjnassignment edge directed edge rj pia set of vertices v and a set of edges e.7.9np
8、rocessnresource type with 4 instancesnpi requests instance of rjnpi is holding an instance of rjpipirjrj7.107.117.127.13nif graph contains no cycles no deadlock.nif graph contains a cycle lif only one instance per resource type, then deadlock.lif several instances per resource type, possibility of d
9、eadlock.7.14nensure that the system will never enter a deadlock state.nallow the system to enter a deadlock state and then recover.nignore the problem and pretend that deadlocks never occur in the system; used by most operating systems, including unix.7.15nmutual exclusion not required for sharable
10、resources; must hold for non-sharable resources.nhold and wait must guarantee that whenever a process requests a resource, it does not hold any other resources.lrequire process to request and be allocated all its resources before it begins execution, or allow process to request resources only when t
11、he process has none.llow resource utilization; starvation possible.restrain the ways request can be made.7.16nno preemption lif a process that is holding some resources requests another resource that cannot be immediately allocated to it, then all resources currently being held are released.lpreempt
12、ed resources are added to the list of resources for which the process is waiting.lprocess will be restarted only when it can regain its old resources, as well as the new ones that it is requesting.ncircular wait impose a total ordering of all resource types, and require that each process requests re
13、sources in an increasing order of enumeration.7.17nsimplest and most useful model requires that each process declare the maximum number of resources of each type that it may need.nthe deadlock-avoidance algorithm dynamically examines the resource-allocation state to ensure that there can never be a
14、circular-wait condition.nresource-allocation state is defined by the number of available and allocated resources, and the maximum demands of the processes.requires that the system has some additional a priori information available.7.18nwhen a process requests an available resource, system must decid
15、e if immediate allocation leaves the system in a safe state.nsystem is in safe state if there exists a sequence of all the processes is the systems such that for each pi, the resources that pi can still request can be satisfied by currently available resources + resources held by all the pj, with j
16、i.nthat is:lif pi resource needs are not immediately available, then pi can wait until all pj have finished.lwhen pj is finished, pi can obtain needed resources, execute, return allocated resources, and terminate. lwhen pi terminates, pi +1 can obtain its needed resources, and so on. 7.19nif a syste
17、m is in safe state no deadlocks.nif a system is in unsafe state possibility of deadlock.navoidance ensure that a system will never enter an unsafe state. 7.207.21nsingle instance of a resource type. use a resource-allocation graphnmultiple instances of a resource type. use the bankers algorithm7.22n
18、claim edge pi rj indicated that process pj may request resource rj; represented by a dashed line.nclaim edge converts to request edge when a process requests a resource.nrequest edge converted to an assignment edge when the resource is allocated to the process.nwhen a resource is released by a proce
19、ss, assignment edge reconverts to a claim edge.nresources must be claimed a priori in the system.7.237.247.25nsuppose that process pi requests a resource rjnthe request can be granted only if converting the request edge to an assignment edge does not result in the formation of a cycle in the resourc
20、e allocation graph7.26nmultiple instances.neach process must a priori claim maximum use.nwhen a process requests a resource it may have to wait. nwhen a process gets all its resources it must return them in a finite amount of time.7.27navailable: vector of length m. if available j = k, there are k i
21、nstances of resource type rj available.nmax: n x m matrix. if max i,j = k, then process pi may request at most k instances of resource type rj.nallocation: n x m matrix. if allocationi,j = k then pi is currently allocated k instances of rj.nneed: n x m matrix. if needi,j = k, then pi may need k more
22、 instances of rj to complete its task. need i,j = maxi,j allocation i,j.let n = number of processes, and m = number of resources types. 7.281. let work and finish be vectors of length m and n, respectively. initialize:work = availablefinish i = false for i = 0, 1, , n- 1.2. find and i such that both
23、: (a) finish i = false(b) needi workif no such i exists, go to step 4.3. work = work + allocationifinishi = truego to step 2.4. if finish i = true for all i, then the system is in a safe state.7.29 request = request vector for process pi. if requesti j = k then process pi wants k instances of resour
24、ce type rj.1. if requesti needi go to step 2. otherwise, raise error condition, since process has exceeded its maximum claim.2. if requesti available, go to step 3. otherwise pi must wait, since resources are not available.3. pretend to allocate requested resources to pi by modifying the state as fo
25、llows:available = available request;allocationi = allocationi + requesti;needi = needi requesti;lif safe the resources are allocated to pi. lif unsafe pi must wait, and the old resource-allocation state is restored7.30n5 processes p0 through p4; 3 resource types: a (10 instances), b (5instances), an
26、d c (7 instances).nsnapshot at time t0:allocationmaxavailablea b ca b c a b cp00 1 07 5 3 3 3 2 p12 0 0 3 2 2 p23 0 2 9 0 2 p32 1 1 2 2 2 p40 0 24 3 3 7.31nthe content of the matrix need is defined to be max allocation.needa b c p07 4 3 p11 2 2 p26 0 0 p30 1 1 p44 3 1 nthe system is in a safe state
27、since the sequence satisfies safety criteria. 7.32ncheck that request available (that is, (1,0,2) (3,3,2) true.allocationneedavailablea b ca b ca b c p00 1 0 7 4 3 2 3 0p13 0 20 2 0 p23 0 1 6 0 0 p32 1 1 0 1 1p40 0 2 4 3 1 nexecuting safety algorithm shows that sequence satisfies safety requirement.
28、 ncan request for (3,3,0) by p4 be granted?ncan request for (0,2,0) by p0 be granted?7.33nallow system to enter deadlock state ndetection algorithmnrecovery scheme7.34nmaintain wait-for graphlnodes are processes.lpi pj if pi is waiting for pj.nperiodically invoke an algorithm that searches for a cyc
29、le in the graph. if there is a cycle, there exists a deadlock.nan algorithm to detect a cycle in a graph requires an order of n2 operations, where n is the number of vertices in the graph.7.35resource-allocation graphcorresponding wait-for graph7.36navailable: a vector of length m indicates the numb
30、er of available resources of each type.nallocation: an n x m matrix defines the number of resources of each type currently allocated to each process.nrequest: an n x m matrix indicates the current request of each process. if request ij = k, then process pi is requesting k more instances of resource
31、type. rj.7.371. let work and finish be vectors of length m and n, respectively initialize:(a) work = available(b)for i = 1,2, , n, if allocationi 0, then finishi = false; otherwise, finishi = true.2. find an index i such that both:(a) finishi = false(b) requesti workif no such i exists, go to step 4
32、. 3. work = work + allocationifinishi = true go to step 2.4.if finishi = false, for some i, 1 i n, then the system is in deadlock state. moreover, if finishi = false, then pi is deadlocked.algorithm requires an order of o(m x n2) operations to detect whether the system is in deadlocked state. 7.38n5
33、 processes p0 through p4; 3 resource types a (7 instances), b (2 instances), and c (6 instances).nsnapshot at time t0: allocationrequestavailablea b c a b c a b cp00 1 0 0 0 0 0 0 0p12 0 0 2 0 2p23 0 30 0 0 p32 1 1 1 0 0 p40 0 2 0 0 2nsequence will result in finishi = true for all i. 7.39np2 requests an additional instance of type c.requesta b c p00 0 0 p12 0 2p20 0 1p31 0 0 p40 0 2nstate of system?lcan
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 产品度合同范例
- 单位租凭员工车辆合同范本
- 中粮销售合同范本
- 化工散水出售合同范本
- seb采购合同范本
- 华为销售合同范本
- 农业采购合同范本格式
- 伐树施工合同范本
- 代理业主房屋合同范本
- 写作委托协议合同范本
- 地理-天一大联考2025届高三四省联考(陕晋青宁)试题和解析
- 小巴掌童话课件
- 教科版六年级科学下册全册教学设计教案
- 部编版小学五年级下册《道德与法治》全册教案含教学计划
- 初中数学新课程标准(2024年版)
- GB/T 19342-2024手动牙刷一般要求和检测方法
- 2024年山东铁投集团招聘笔试参考题库含答案解析
- 8款-组织架构图(可编辑)
- 中学生班干部培训方案(共4页)
- 净土资粮——信愿行(11)第六讲净业三福变化气质
- 美的集团公司分权手册
评论
0/150
提交评论