Deadlock is a situation which involves the interaction of more than one resources and processes with each other.
We can visualise the occurrence of deadlock as a situation where there are two people on a staircase. One is ascending the staircase while the other is descending. The staircase is so narrow that it can only fit one person at a time. As a result, one has to retreat while the others moves on and uses the staircase. Once that person is finished, the other one can use that staircase. But here, none of the people is willing to retreat and waits for the each other to retreat. None of them is able to use the staircase. The people here is the process and the staircase is the resource.
When a process requests for the resource that is been held another process which needs another resource to continue, but is been held by the first process, then it is called a deadlock.
There are 4 conditions necessary for the occurrence of a deadlock. They can be understood with the help of the above illustrated example of staircase :
- Mutual Exclusion:
When two people meet in the landings, they can’t just walk through because there is space only for one person. This condition to allow only one person (or process) to use the step between them (or the resource) is the first condition necessary for the occurrence of the deadlock.
- Hold and Wait:
When the 2 people refuses to retreat and hold their grounds, it is called holding. This is the next necessary condition for the the deadlock.
- No Preemption:
For resolving the deadlock one can simply cancel one of the processes for other to continue. But Operating System doesn’t do so. It allocates the resources to the processors for as much time needed until the task is completed. Hence, there is no temporary reallocation of the resources. It is third condition for deadlock.
- Circular Wait:
When the two people refuses to retreat and wait for each other to retreat, so that they can complete their task, it is called circular wait. It is the last condition for the deadlock to occur.
All the 4 conditions are necessary for the deadlock to occur. If any one is prevented or resolved, the deadlock is resolved.
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.
- Deadlock Ignorance in Operating System
- Recovery from Deadlock in Operating System
- Introduction of Deadlock in Operating System
- Deadlock Detection Algorithm in Operating System
- Program for Deadlock free condition in Operating System
- Bernstein's Conditions in Operating System
- Operating Systems | Deadlock | Question 2
- Operating Systems | Deadlock | Question 1
- Hierarchical Deadlock Detection in Distributed System
- File System Implementation in Operating System
- Difference between Deadlock Prevention and Deadlock Avoidance
- System Protection in Operating System
- System Programs in Operating System
- Concurrency in Operating System
- Best-Fit Allocation in Operating System
- Inode in Operating System
- Bad Block in Operating system
- Multithreading in Operating System
- Functions of Operating System
- Introduction of Operating System - Set 1
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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.