What is Deadlock?
Deadlock happens when a group of processes is stuck, unable to continue because each one is waiting for a resource that another process in the group is holding. This situation is permanent because none of the processes can move forward.
Example of Deadlock:
Think of a traffic deadlock at a four-way stop where four cars arrive at the same time, each trying to go straight through the intersection:
If all cars follow the rule of yielding to the car on their right, they will all stop because they are all waiting for each other. In this case, each car has taken control of one quadrant but cannot move because they need another quadrant that is already blocked by another car. This is an actual deadlock.
In computers, processes often compete for resources (like memory or files). Consider two processes, P and Q, that need two resources, A and B. They might follow this order:
This could lead to a deadlock: