- 69 Views
- Uploaded on
- Presentation posted in: General

DEADLOCK AVOIDANCE

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

DEADLOCK AVOIDANCE

CLASS SCRIBE – 19.4.2013

Prepared by –

shushmanchoudhury (11cs10061)

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.

R1

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.

Assignment

Edge

Request

Edge

P1

P2

Claim Edge

R2

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.

R1

R1

P1

P2

P1

P2

R2

R2

ACTUAL DEADLOCK

POTENTIAL DEADLOCK

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.

The Banker’s 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.

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 Mij is the number of maximum instances of resource Rj needed by process Pi

Need Matrix – An nXm matrix where Nij indicates that Pi may need Rjmore resources to complete its task.

Request represents request vector for process Pi.

If Requesti[j] = k then process Pi wants k instances of resource type Rj

1.If Requesti Needigo to step 2. Otherwise, an error is thrown, since the process has exceeded its maximum claim.

2.If Requesti Available, go to step 3. Otherwise Pi must wait, since its desired resources are not available at that moment.

3.Hypothetically allocate requested resources to Pi by modifying the state as follows:

Available = Available –Requesti;

Allocationi= Allocationi + Requesti;

Needi=Needi – Requesti;

- If safe the resources are allocated to Pi
- If unsafe Pi must wait, and the old resource-allocation state is restored

1.Let Work and Finish be vectors of length m and n, respectively. Initialize:

Work = Available

Finish [i] = false fori = 0, 1, …, n- 1

2.Find an isuch that both:

(a) Finish [i] = false

(b) Needi Work

If no such iexists, go to step 4

3. Work = Work + AllocationiFinish[i] = truego to step 2

4.If Finish [i] == true for all i, then the system is in a safe state