Card 05/ 08
All 8 cards
ComparisonDifficulty: Advanced1 min
Deadlock, Livelock and Starvation
Three failures that all look like "the work is not getting done" from outside, and need three different fixes. Telling them apart takes about a minute with a thread dump and saves a day.
| Failure | The threads are | Processor use | Fixed by |
|---|---|---|---|
| Deadlock | Blocked forever, in a cycle | Idle | A lock ordering |
| Livelock | Running, reacting to each other, making no progress | High | Randomised backoff, or one decider |
| Starvation | Running, but one of them never gets its turn | High | Fairness, or priority |
Livelock is the one people have not met. Two threads each notice the other is waiting, each politely backs off and retries, and the timing means they collide again — like two people stepping aside in a corridor, repeatedly.
Starvation is one thread losing every race. A lock with no fairness hands itself to whoever asks at the right moment, and a thread that always asks at the wrong moment can wait indefinitely while its neighbours are served.
The decision rule for diagnosing one. Look at the processor first. Idle threads that are not moving is a deadlock. Busy threads that are not finishing is a livelock. Busy threads where most finish and one does not is starvation.