operatingsystem操作系統(tǒng)ch07deadlocks44_第1頁(yè)
operatingsystem操作系統(tǒng)ch07deadlocks44_第2頁(yè)
operatingsystem操作系統(tǒng)ch07deadlocks44_第3頁(yè)
operatingsystem操作系統(tǒng)ch07deadlocks44_第4頁(yè)
operatingsystem操作系統(tǒng)ch07deadlocks44_第5頁(yè)
已閱讀5頁(yè),還剩38頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

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等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論