Deadlock requires all four Coffman conditions to be true simultaneously. Break any one, and deadlock becomes impossible.
Condition 1: Mutual Exclusion
Resources cannot be shared. If Thread A holds a lock, Thread B cannot also hold it. This is fundamental to most synchronization - we cannot eliminate it without redesigning the system.
Condition 2: Hold and Wait
Threads hold resources while waiting for more. If threads had to request all resources at once (and release all if any unavailable), this condition would be broken.
Condition 3: No Preemption
Resources cannot be forcibly taken. A thread holds its lock until it voluntarily releases. If the system could revoke locks, deadlock could be broken - but this introduces other problems.
Condition 4: Circular Wait
A cycle of threads exists where each waits for a resource held by the next. Thread A waits for B, B waits for C, C waits for A. This is the smoking gun of deadlock.
All Four Must Be True
Prevention Strategy: Most deadlock prevention focuses on breaking condition 4 (circular wait) by imposing a lock ordering. This is often the easiest to control in practice.
💡 Key Takeaways
✓Coffman conditions: Mutual Exclusion, Hold and Wait, No Preemption, Circular Wait. All four required.
✓Break any one condition and deadlock is impossible. Most systems target circular wait.
✓Mutual exclusion is usually necessary - we need locks. Hard to eliminate.
✓Hold and wait can be prevented by acquiring all locks atomically, but this is often impractical.
✓Circular wait is prevented by lock ordering - always acquire locks in the same global order.
📌 Examples
1No hold-and-wait: Thread must request Lock A and Lock B together. If B busy, release A and retry.
2No circular wait: All threads must acquire Lock 1 before Lock 2. No cycles possible.
3Preemption (rare): Database can abort one transaction to break deadlock. Victim retries.