Deadlock Prevention

We can prevent a Deadlock by eliminating any of the above four conditions. 

Eliminate Mutual Exclusion: It is not possible to dis-satisfy the mutual exclusion because some resources, such as the tape drive and printer, are inherently non-shareable. 

Eliminate Hold and wait: Allocate all required resources to the process before the start of its execution, this way hold and wait condition is eliminated but it will lead to low device utilization. for example, if a process requires a printer at a later time and we have allocated a printer before the start of its execution printer will remain blocked till it has completed its execution. The process will make a new request for resources after releasing the current set of resources. This solution may lead to starvation.
 

Eliminate No Preemption : Preempt resources from the process when resources are required by other high-priority processes. 

Eliminate Circular Wait : Each resource will be assigned a numerical number. A process can request the resources to increase/decrease. order of numbering. For Example, if the P1 process is allocated R5 resources, now next time if P1 asks for R4, R3 lesser than R5 such a request will not be granted, only a request for resources more than R5 will be granted. 

Detection and Recovery: Another approach to dealing with deadlocks is to detect and recover from them when they occur. This can involve killing one or more of the processes involved in the deadlock or releasing some of the resources they hold.

Deadlock Prevention And Avoidance

When two or more processes try to access the critical section at the same time and they fail to access simultaneously or stuck while accessing the critical section then this condition is known as Deadlock.

  1. Every process needs a few resources to finish running. 
  2. The procedure makes a resource request. If the resource is available, the OS will grant it; otherwise, the process will wait.
  3. When the process is finished, it is released.

Similar Reads

Deadlock Characteristics

The deadlock has the following characteristics:...

Deadlock Prevention

We can prevent a Deadlock by eliminating any of the above four conditions....

Deadlock Avoidance

A deadlock avoidance policy grants a resource request only if it can establish that granting the request cannot lead to a deadlock either immediately or in the future. The kernal lacks detailed knowledge about future behavior of processes, so it cannot accurately predict deadlocks. To facilitate deadlock avoidance under these conditions, it uses the following conservative approach: Each process declares the maximum number of resource units of each class that it may require. The kernal permits a process to request these resource units in stages- i.e. a few resource units at a time- subject to the maximum number declared by it and uses a worst case analysis technique to check for the possibility of future deadlocks. A request is granted only if there is no possibility of deadlocks; otherwise, it remains pending until it can be granted. This approach is conservative because a process may complete its operation without requiring the maximum number of units declared by it....

Conclusion

Operating Systems employ deadlock avoidance to prevent deadlock by using the Banker’s algorithm or the resource allocation graph.Deadlock avoidance works by informing the operating system of the resources needed by the process to finish execution, and the operating system then determines whether or not the requirements can be met....

Frequently Asked Questions

Q.1: What is deadlock prevention?...