What is Deadlock?
You'll learn what deadlock means and why it's one of the most serious synchronization problems in concurrent systems.
The Core Problem
Deadlock occurs when two or more processes (or threads) become permanently blocked, each waiting for a resource held by another process in the cycle. No process can proceed, and they're stuck forever unless external intervention breaks the deadlock.
Think of it like two cars meeting face-to-face on a narrow one-lane bridge. Neither can move forward because the other is blocking the way, and neither wants to back up. They're deadlocked.
The Four Necessary Conditions
For deadlock to occur, all four of these conditions must be present simultaneously:
- Mutual Exclusion: At least one resource must be held in a non-shareable mode (only one process can use it at a time)
- Hold and Wait: A process holding at least one resource is waiting to acquire additional resources held by other processes
- No Preemption: Resources cannot be forcibly taken away; they must be voluntarily released by the holding process
- Circular Wait: A circular chain of processes exists, where each process holds a resource needed by the next process in the chain
A Concrete Example
Imagine Process A holds Lock 1 and needs Lock 2, while Process B holds Lock 2 and needs Lock 1. Both are stuck waiting for each other—classic deadlock. This is the lock ordering problem you may have encountered when working with multiple mutexes.
Unlike a race condition (where timing determines correctness) or starvation (where a process is delayed indefinitely but others progress), deadlock means the entire set of processes is completely stuck.
Key Takeaway: Deadlock is a permanent blocking condition where processes wait for each other in a cycle, requiring all four conditions (mutual exclusion, hold-and-wait, no preemption, circular wait) to occur simultaneously.