Presentation is loading. Please wait.

Presentation is loading. Please wait.


Similar presentations

Presentation on theme: "CLASS SCRIBE – 19.4.2013 PREPARED BY – SHUSHMAN CHOUDHURY (11CS10061) DEADLOCK AVOIDANCE."— Presentation transcript:


2 AVOIDANCE WITH A SINGLE RESOURCE The Resource Allocation Graph must be used. It will be similar to that shown previously, but with an additional edge called Claim Edge that represents the potential requirements of the process. The process lets the system know what it may require right from the beginning. Resources must be claimed apriori. A cycle in this augmented resource allocation graph will imply the possibility of a deadlock in the near future.

3 THE RESOURCE ALLOCATION GRAPH WITH CLAIM EDGE The assignment edge shows that R1 has been assigned to P1, and the request edge shows that P2 has requested resource R1, as has been explained before. Furthermore, the claim edges (dotted lines) show that both P1 and P2 may request R2 in the near future. R1 P1 R2 P2 Claim Edge Assignment Edge Request Edge

4 CYCLES WITH CLAIM EDGES The claim edge will become the resource edge when the process requests that resource. This in turn becomes an assignment edge when the resource is granted to the process. Therefore, just as a cycle with request and assignment edges indicates a deadlock, the same with a claim edge indicates a possible deadlock, and consequently, an unsafe state. Thus, the request can be granted only if such a cycle does not exist, i.e the state is safe.

5 EFFECT OF INCORRECT HANDLING R1 P1 R2 P2 R1 P1 R2 P2 As can be observed here, this is what will happen if the cycles with claim edges are not taken care of. Over time, a deadlock may arise if the claim edge becomes a request edge before the other resource is let go. POTENTIAL DEADLOCK ACTUAL DEADLOCK

6 AVOIDANCE - MULTIPLE RESOURCES The Bankers Algorithm is used for this purpose. The algorithm is principally similar to the previously studied deadlock detection method, albeit with a few modifications. Processes must inform the system of their maximum resource usage apriori. As soon as a set of resources is requested, the system must gauge the safety of the potential allocation. It will not proceed otherwise. Furthermore, resources must be returned in a finite time.

7 DATA STRUCTURES Available Vector – A vector of length m where m is the number of resources, indicating the number of available resources of each type. Allocation Matrix – As described before. Maximum Matrix – An nXm matrix where M ij is the number of maximum instances of resource R j needed by process P i Need Matrix – An nXm matrix where N ij indicates that P i may need R j more resources to complete its task.

8 RESOURCE REQUEST ALGORITHM Request represents request vector for process P i. If Request i [j] = k then process P i wants k instances of resource type R j 1.If Request i Need i go to step 2. Otherwise, an error is thrown, since the process has exceeded its maximum claim. 2.If Request i Available, go to step 3. Otherwise P i must wait, since its desired resources are not available at that moment. 3.Hypothetically allocate requested resources to P i by modifying the state as follows: Available = Available – Request i ; Allocation i = Allocation i + Request i ; Need i = Need i – Request i ; l If safe the resources are allocated to Pi l If unsafe Pi must wait, and the old resource-allocation state is restored

9 SAFETY ALGORITHM 1.Let Work and Finish be vectors of length m and n, respectively. Initialize: Work = Available Finish [i] = false for i = 0, 1, …, n- 1 2.Find an i such that both: (a) Finish [i] = false (b) Need i Work If no such i exists, go to step 4 3. Work = Work + Allocation i Finish[i] = true go to step 2 4.If Finish [i] == true for all i, then the system is in a safe state


Similar presentations

Ads by Google