Card 08/ 08

RecapDifficulty: Advanced1 min

Recap: Deadlock and the Failures Near It

The cycle, the four conditions, the ordering fix, and the stalls that look like it, with where each was.

Deadlock and its neighbours come down to the five ideas below, each listed with the card that covers it.

What the topic established, and which card it was on
The ideaWhere
A deadlock is a cycle of threads each holding what another wantsDeadlock: Two Threads Each Waiting for the Other's Lock
Two correct methods taking the same locks in opposite orders are enoughDeadlock Example: A Transfer Run in Both Directions at Once
Four conditions must hold at once; removing any one prevents itThe Four Conditions for Deadlock
A global lock order removes circular wait at no costPreventing Deadlock With a Global Lock Order
Idle and stuck is deadlock; busy and stuck is livelockDeadlock vs Livelock vs Starvation

No single method can deadlock on its own, so no amount of reading one method will find it. A deadlock comes from two pieces of code disagreeing about an order, and the fix is a decision the whole program keeps.