Open In App

Difference between Deadlock Prevention and Deadlock Avoidance

Last Updated : 15 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Deadlock is a condition where a set of processes becomes stuck and waits infinitely for the resources which are hold by other processes. To handle these types of problems, we use two strategies - Deadlock Prevention and Deadlock Avoidance.

Deadlock Prevention means blocking one of the conditions necessary for deadlock while deadlock avoidance refers to managing resource allocation in such a way that is safe and avoids unsafe states.

What is Deadlock Prevention?

Deadlock prevention means blocking at least one of the four conditions required for deadlock to occur. If we are able to block any one of them then deadlock can be prevented. 

The four conditions which need to be blocked are:- 

  • Mutual Exclusion
  • Hold and Wait
  • No Preemption
  • Circular Wait

Spooling and non-blocking synchronization algorithms are used to prevent the above conditions. In deadlock prevention, all the requests are granted in a finite amount of time. 

Advantages of Deadlock Prevention

  • Prevents deadlock by eliminating one of the necessary conditions.
  • Ensures that resource requests are handled in a finite amount of time.

Disadvantages of Deadlock Prevention

  • Can lead to low device utilization as the system may under-utilize resources to avoid deadlock.
  • May impose constraints on the system's resource allocation process.

What is Deadlock Avoidance ?

In Deadlock avoidance we have to anticipate deadlock before it really occurs and ensure that the system does not go in unsafe state.It is possible to avoid deadlock if resources are allocated carefully. For deadlock avoidance we use Banker's and Safety algorithm for resource allocation purpose. In deadlock avoidance the maximum number of resources of each type that will be needed are stated at the beginning of the process. 

Advantages of Deadlock Avoidance

  • Dynamically allocates resources to avoid deadlock, leading to efficient resource utilization.
  • Provides a flexible approach that adapts to the current system state.

Disadvantages of Deadlock Avoidance

  • Requires knowledge of future resource requests, which may not always be available.
  • May lead to blocking processes for extended periods while ensuring safety.

Difference between Deadlock Prevention and Deadlock Avoidance 

FactorsDeadlock PreventionDeadlock Avoidance
ConceptIt blocks at least one of the conditions necessary for deadlock to occur.It ensures that system does not go in unsafe state
Resource RequestAll the resources are requested together.Resource requests are done according to the available safe path.
Information requiredIt does not requires information about existing resources, available resources and resource requestsIt requires information about existing resources, available resources and resource requests
ProcedureIt prevents deadlock by constraining resource request process and handling of resources.It automatically considers requests and check whether it is safe for system or not.
PreemptionSometimes, preemption occurs more frequently.In deadlock avoidance there is no preemption.
Resource allocation strategyResource allocation strategy for deadlock prevention is conservative.Resource allocation strategy for deadlock avoidance is not conservative.
Future resource requestsIt doesn't requires knowledge of future process resource requests.It requires knowledge of future process resource requests.
AdvantageIt doesn't have any cost involved because it has to just make one of the conditions false so that deadlock doesn't occur.There is no system under-utilization as this method works dynamically to allocate the resources.
DisadvantageDeadlock prevention has low device utilization.Deadlock avoidance can block processes for too long.
ExampleSpooling and non-blocking synchronization algorithms are used.Banker's and safety algorithm is used.

Conclusion

Deadlock Prevention eliminates one of the necessary conditions for deadlock, but it may result in under-utilization of resources. On the other hand, Deadlock Avoidance allocates resources to avoid deadlock, but it requires information about future resource requests which may cause process delays. We need to choose the right strategy depending on the system requirements and resource demand.


Next Article

Similar Reads