What are the different methods of handling deadlock?

There are three deadlock handling strategies :

Deadlock Prevention :

  • There are four necessary conditions for deadlock to occur i.e. mutual exclusion, hold and wait, no preemption & circular wait. By ensuring that at least one of these conditions cannot hold, we can prevent the occurrence of a deadlock.
  • Possible side effects of preventing deadlocks by this method are low device utilization and reduced system throughput.

Deadlock Avoidance :

  • A deadlock-avoidance algorithm dynamically examines the resource-allocation state to ensure that a circular-wait condition can never exist. The resource allocation state is defined by the number of available and allocated resources and the maximum demands of the processes.
  • The idea is simply to ensure that the system will always remain in a safe state. Initially, the system is in a safe state.
  • Whenever a process requests a resource that is currently available, the system must decide whether the resource can be allocated immediately or whether the process must wait. The request is granted only if the allocation leaves the system in a safe state.
  • In this scheme, if a process requests a resource that is currently available, it may still have to wait. Thus, resource utilization may be lower.
  • There are 2 algorithms for deadlock avoidance :
    1. Resource Allocation Graph Algorithm
    2. Banker’s Algorithm

Deadlock detection and recovery:

  • This method involves letting the deadlock to occur and then handle it.
  • If all resources have only a single instance, then we can define a deadlock detection algorithm that uses a variant of the resource-allocation graph, called a wait-for graph.
  • If there are multiple instances of same resource, wait for graphs are not useful. A different deadlock detection algorithm is used.
  • After detecting deadlock, for Deadlock Recovery :
    1. Process Termination : To eliminate deadlocks by aborting a process, we use one of two methods : abort all deadlocked processes and abort one process at a time until the deadlock cycle is eliminated.
    2. Resource Preemption : To eliminate deadlocks using resource preemption, we successively preempt some resources from processes and give these resources to other processes until the deadlock cycle is broken.

Leave a Reply

Your email address will not be published. Required fields are marked *