What is Deadlock and Starvation?
Deadlock and starvation, told as a story about two mechanics each holding a key the other needs.
Two mechanics each hold a different key and wait for the other's.Neither lets go — each just stares at the other's key.
Deadlock needs all four conditions to hold at once.Break just one, and deadlock can't happen.
Deadlock = freezing forever while each waits on the other's key.Neither can move — not without someone stepping in.
There are four strategies for handling deadlock.In practice, "ignore" (the ostrich algorithm) is common.
Starvation — the garage keeps running, but one car keeps getting bumped.The garage isn't frozen — only this car's turn never arrives.
Deadlock = freezing forever as each side holds one resource (key) and waits on another. Starvation isn't frozen — one side just never gets its turn.
Deadlock arises when four conditions hold at once: Mutual Exclusion, Hold and Wait, No Preemption, and Circular Wait. Fixes include prevention (design away one condition), avoidance (allow only safe states, as in the banker's algorithm), detection-and-recovery, or simply ignoring it (the ostrich algorithm). Starvation differs from deadlock: the system keeps running, but one process never gets the resource it needs because of scheduling or priority.
When grown-ups say it
- Mutual Exclusion
- One key, one holder at a time. One of the four conditions for deadlock.
- Circular Wait
- Everyone waiting in a loop for the next one's key. Break this waiting loop, and the deadlock breaks too.
- Starvation
- One car keeps getting bumped down the order. Not a freeze — an endless postponement.
- CPU Scheduling
- The rule that sets the car order on the board. A priority rule can itself cause starvation. → who gets the lift first
- Synchronization
- The rule for handing out the lift key. Deadlock often comes from misusing synchronization tools. → there's only one lift key
- Process/Thread
- Several hands working the same car. Deadlock can happen between threads or between processes. → one car, many hands
- Virtual Memory
- A fake map that makes the whole warehouse look like mine. Another example of sharing a limited resource. → the fake map that makes the whole warehouse yours
- Orchestration
- The SRE field's version of ordering work. Distributed systems handle resource deadlock in a similar spirit. → orchestration in the SRE field