Deadlocks
When processes wait forever â and the four conditions that cause it.
What is a Deadlock?
A deadlock happens when two or more processes are each waiting for a resource held by another, and none can proceed â like two people each waiting for the other to move first in a narrow hallway.
Four Necessary Conditions
Mutual Exclusion (resource can't be shared), Hold and Wait (a process holds one resource while waiting for another), No Preemption (resources can't be forcibly taken), and Circular Wait (a cycle of processes each waiting on the next).
Handling Deadlocks
Strategies include Prevention (break one of the four conditions), Avoidance (like the Banker's Algorithm, which checks if granting a resource keeps the system in a safe state), and Detection & Recovery (allow deadlocks but detect and resolve them).
đ Real-World Use
Database systems detect deadlocks when two transactions each lock a row the other needs â most databases automatically detect this and roll back one transaction to break the cycle, rather than letting both hang forever.
đĄ Pro Tip
A simple way to remember the four conditions: 'MHNC' â Mutual exclusion, Hold and wait, No preemption, Circular wait. ALL FOUR must be true simultaneously for a deadlock â removing even one prevents it.
đ§Ē Quick Self-Test
Check what you just learned â no pressure, just practice.
1. How many necessary conditions must hold for a deadlock to occur?
2. What does 'Circular Wait' mean?