Presentation is loading. Please wait.

Presentation is loading. Please wait.

DEADLOCKS Prepared By: Dr. Vipul Vekariya. D EADLOCK A set of processes is deadlocked when each process in the set is blocked awaiting an event that can.

Similar presentations


Presentation on theme: "DEADLOCKS Prepared By: Dr. Vipul Vekariya. D EADLOCK A set of processes is deadlocked when each process in the set is blocked awaiting an event that can."— Presentation transcript:

1 DEADLOCKS Prepared By: Dr. Vipul Vekariya

2 D EADLOCK A set of processes is deadlocked when each process in the set is blocked awaiting an event that can only be triggered by another blocked process in the set Typically involves processes competing for the same set of resources.

3 P OTENTIAL D EADLOCK I need quad A and B I need quad B and C I need quad C and D I need quad D and A

4 A CTUAL D EADLOCK HALT until B is free HALT until C is free HALT until D is free HALT until A is free

5 C ONDITIONS FOR POSSIBLE D EADLOCK Deadlock can arise if four conditions hold simultaneously. Mutual exclusion Resource must be allocate to process any time in an exclusive manner and not on a shared basis. Hold-and-wait Even if process hold certain resource at any moment, it should be possible for it to request for new ones. No pre-emption if a process holds certain resources, no other process should be able to take them away from it forcibly.

6 A CTUAL D EADLOCK R EQUIRES … All previous 3 conditions plus: Circular wait A closed chain of processes exists, such that each process holds at least one resource needed by the next process in the chain It is necessary to understand that all these four conditions have to be satisfied simultaneously for the existence of dead lock. If anyone of them does not exist, a deadlock can be avoided.

7 D EALING WITH D EADLOCK Three general approaches exist for dealing with deadlock. Ignore it Detect Deadlock Recover from it Avoid it Prevent it

8 D IRECTED R ESOURCE A LLOCATION G RAPHS (DRAG) Directed graph that depicts a state of the system of resources and processes

9 R ESOURCE A LLOCATION G RAPHS OF DEADLOCK

10 R ESOURCE A LLOCATION G RAPHS

11 R ECOVERY FROM DEADLOCK Recovery through preemption Recover through rollback Recovery through killing a process 11

12 D EADLOCK A VOIDANCE A decision is made dynamically whether the current resource allocation request will, if granted, potentially lead to a deadlock Requires knowledge of future process requests

13 T WO A PPROACHES TO D EADLOCK A VOIDANCE Process Initiation Denial Do not start a process if its demands might lead to deadlock Resource Allocation Denial Do not grant an incremental resource request to a process if this allocation might lead to deadlock

14 R ESOURCE A LLOCATION D ENIAL Referred to as the banker’s algorithm A strategy of resource allocation denial Consider a system with fixed number of resources State of the system is the current allocation of resources to process Safe state is where there is at least one sequence that does not result in deadlock Unsafe state is a state that is not safe

15 15 S AFE AND U NSAFE S TATES Demonstration that the state in (a) is safe (a) (b) (c) (d) (e)

16 16 S AFE AND U NSAFE S TATES Demonstration that the sate in b is not safe (a) (b) (c) (d)

17 17 T HE B ANKER ' S A LGORITHM FOR A S INGLE R ESOURCE Three resource allocation states (a)safe (b)safe (c) unsafe (a) (b) (c)

18 B ANKER ’ S A LGORITHM FOR MULTIPLE RESOURCES A system consisting of four processes and three resources. Allocations are made to processors Is this a safe state? Amount of Existing Resources Resources available after allocation

19 P ROCESS I C ij - A ij ≤ V j, for all j This is not possible for P1, which has only 1 unit of R1 and requires 2 more units of R1, 2 units of R2, and 2 units of R3. If we assign one unit of R3 to process P2, Then P2 has its maximum required resources allocated and can run to completion and return resources to ‘available’ pool

20 A FTER P2 RUNS TO COMPLETION Can any of the remaining processes can be completed? Note P2 is completed

21 A FTER P1 COMPLETES

22 P3 C OMPLETES Thus, the state defined originally is a safe state.

23 D ETERMINATION OF AN U NSAFE S TATE This time Suppose that P1 makes the request for one additional unit each of R1 and R3. Is this safe?

24 D EADLOCK A VOIDANCE When a process makes a request for a set of resources, assume that the request is granted, Update the system state accordingly, Then determine if the result is a safe state. If so, grant the request and, if not, block the process until it is safe to grant the request.

25 D EADLOCK A VOIDANCE R ESTRICTIONS Maximum resource requirement must be stated in advance Processes under consideration must be independent and with no synchronization requirements There must be a fixed number of resources to allocate No process may exit while holding resources

26 D EADLOCK PREVENTION 26


Download ppt "DEADLOCKS Prepared By: Dr. Vipul Vekariya. D EADLOCK A set of processes is deadlocked when each process in the set is blocked awaiting an event that can."

Similar presentations


Ads by Google