Sei sulla pagina 1di 2
7.53.1 Safety Algorithm We can now present the algorithm for finding out whether or not a system is ina safe state. This algorithm can be described as follows: 1. Let Work and Finish be vectors of length m and x, respectively. Initialize Work = Available and Fintish{i] = false for i= 0,1, ..."- 1 2. Find an i such that both a. Finishfi] b. Need; < Work Ise Ifno such i exists, go to step 4. 3. Work = Work + Allocation; Finish{i] = true Goto step 2. 4, If Finish{i] == true for all i, then the system is in a safe state. Thisalgorithm may require an order of m x 1° operations to determine whether asstate is safe. 7532. Resource-Request Algorithm ‘We now describe the algorithm which determines if requests can be safely grantee. Let Request; be the request vector for process P). If Request; [j] == &, then process P; wants k instances of resource type R;. When a request for resources is made by process P;, the following actions are taken: 1. Le Request; < Need, go to step 2. Otherwise, aise an error condition, since the process has exceeded its maximum claim, 75 Deadlock Avoidance 261 2 IE Request; = Avuilable, go to step 3. Otherwise, P, must wait, since the sesoutces are not available. 3. Have the system pretend to have allocated the requested resources to process P, by modifying the state as follows: Available = Available - Request; Allocation, = Allocation, + Request Nees = Need,» Request, If the resulting resource-allocation state is safe, the transaction is com- pleted, and process 7 is allocated its resources, However, ifthe new state Js unsafe, then P, must wait for Reyiest,,and the ole resource-allocation state is restored, 7.533 An IMlustrative Example Finally to illustrate the use of the banker's algorithm, consider a system with, fave processes Py through Py and three resource types A. B. and C. Resource type A has 10 instances, resource type B has 5 instances, and resource type C hhas 7 instances. Suppose that, at time Tp, the following snapshot of the system Jhas been taken Allocation Max Availabe ABC ABC ABC % 010753332 PR 2000-322 F302 902 211222 P 002,433 ‘The content of the matrix New is defined to be Max — Allocation and is as. follows: Nec ABC 743 122 600 on Po 431 We claim that the system is currently in a safe state, Incleed, the sequence P,, Ps, Py, Ps, Py> satisfies the safety criteria. Suppose now that process », requests one additional instance of resource type A and two instances of resource type €, 50 Request; = (102). To decide whether this request can be Immediately granted, we fitst check that Reguest; = Avuilable—that is, that (1.0.2) = (@3,3,2), which is true, We then pretend that this request has been fulfilled, and we arrive atthe following new state:

Potrebbero piacerti anche