DeadlocksLivelock & StarvationMedium⏱️ ~2 min

What is Starvation?

Definition
Starvation occurs when a thread waits indefinitely while other threads keep making progress. The thread is not deadlocked - it could run, but it never gets the chance.

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.

The Key Insight: Starvation is "progress for some, waiting forever for others." The system keeps running. Requests keep being served. Just not that one thread sitting in the corner.
💡 Key Takeaways
Starvation means indefinite waiting while others make progress - you could run but never do
Common causes: priority inversion, unfair scheduling, greedy resource access patterns
Classic example: readers-writers where continuous readers starve writers
Bounded waiting requirement: thread wait time must be provably finite
Different from deadlock: system makes progress, just not for the starving thread
📌 Examples
1Readers-writers: new readers keep arriving, writers wait forever to update the database
2Priority scheduling: low-priority background tasks never run during busy hours
3Lock acquisition: thread keeps losing races to acquire mutex against faster threads
← Back to Livelock & Starvation Overview
What is Starvation? | Livelock & Starvation - System Overflow