Difference between Deadlock Prevention and Deadlock Avoidance

1. Deadlock Prevention :
Deadlock prevention means to block 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:-

  1. Mutual Exclusion
  2. Hold and Wait
  3. No Preemption
  4. 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.

2. 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.



Difference between Deadlock Prevention and Deadlock Avoidance :



S.NO. Factors Deadlock Prevention Deadlock Avoidance
1. Concept It blocks at least one of the conditions necessary for deadlock to occur. It ensures that system does not go in unsafe state
2. Resource Request All the resources are requested together. Resource requests are done according to the available safe path.
3. Information required It does not requires information about existing resources, available resources and resource requests It requires information about existing resources, available resources and resource requests
4. Procedure It 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.
5. Preemption Sometimes, preemption occurs more frequently. In deadlock avoidance there is no preemption.
6. Resource allocation strategy Resource allocation strategy for deadlock prevention is conservative. Resource allocation strategy for deadlock prevention is not conservative.
7. Future resource requests It doesn’t requires knowledge of future process resource requests. It requires knowledge of future process resource requests.
8. Advantage It 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 resuorces.
9. Disadvantage Deadlock prevention has low device utilization. Deadlock avoidance can block processes for too long.
10. Example Spooling and non-blocking synchronization algorithms are used. Banker’s and safety algorithm is used.

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.