Deadlock Handling



A Deadlock is a situation where each of the computer process waits for a resource which is being assigned to some another process. In this situation, none of the process gets executed since the resource it needs, is held by some other process which is also waiting for some other resource to be released. A deadlock may be thought of as indefinite starvation. In the below example, P1 requires resource R1 which is held by P2, but P2 requires resource R1 which is held by P1. This causes both processes to wait indefinitely.

deadlock

The four conditions mentioned below must all be followed simultaneously to achieve deadlock:

  1. Mutual exclusion
  2. Hold and wait
  3. No Preemption
  4. Circular Wait

The following strategies are used for handling deadlocks:

  1. Deadlock Ignorance
  2. Deadlock Prevention
  3. Deadlock Avoidance
  4. Deadlock Detection and Recovery




Card image

Bankers Algorithm

Banker's algorithm is one such deadlock avoidance algorithm

Learn about Banker's Algorithm



Preventing recursive locks

This prevents a single thread from entering the same lock more than once.