What is Starvation?
The Restaurant Analogy
Picture a busy restaurant with one waiter. VIP guests keep arriving and get served first. A regular customer who arrived early keeps waiting. Other people eat and leave, eat and leave. But that one customer? Still waiting. They are not stuck at the door (that would be deadlock). The door is open. They just never reach the front of the line.
Why Starvation Happens
Priority inversion: High-priority threads always run first. A low-priority thread may wait forever if high-priority work keeps arriving.
Unfair scheduling: Some threads consistently win when competing for resources. The scheduler does not guarantee fairness.
Greedy algorithms: Readers-writers problem is the classic example. If new readers keep arriving before old ones leave, writers starve. The door to write is open, but there is always someone reading.
The Bounded Waiting Requirement
For most applications, starvation is unacceptable. We enforce bounded waiting: the time a thread waits must be provably finite. This is not just about semaphores. The scheduler plays a role too. If a thread is never scheduled, it starves no matter what your code does.