Causes of Starvation: Unfair Scheduling
What you'll learn: How thread priority, unfair locks, and greedy threads can starve other threads of CPU time and lock access.
The Core Problem
Starvation happens when a thread is perpetually denied the resources it needs to make progress. Unlike deadlock (where threads are stuck forever) or livelock (where threads actively prevent each other), starvation occurs when the scheduling system consistently favors some threads over others.
Primary Causes
Thread Priority Imbalance
When high-priority threads continuously arrive or consume CPU time, low-priority threads may never get scheduled. The scheduler gives preference to high-priority work, leaving low-priority threads waiting indefinitely. Remember: relying on priority is risky—the scheduler isn't obligated to be fair.
Unfair Lock Policies
Some locking mechanisms don't guarantee first-come-first-served access. When multiple threads compete for a lock, an "unfair" policy may repeatedly grant the lock to the same thread or favor recently-waiting threads over long-waiting ones. Threads that happen to request at "unlucky" times get perpetually skipped.
Greedy Thread Behavior
A thread that holds a lock for extended periods or continuously re-acquires a lock immediately after releasing it can starve others. Imagine a thread processing a queue in a tight loop—it releases the lock briefly, but grabs it again before waiting threads can react.
Resource Monopolization
When threads don't yield or share resources proportionally, starvation occurs. A thread performing long computations in a synchronized block prevents others from making any progress, even if they only need brief access.
Analogy
Think of a restaurant where VIP customers (high-priority threads) always get seated first, and busy waiters (unfair locks) keep serving the same tables. Regular customers may wait hours while VIPs keep arriving and being served immediately.
Key Takeaway: Starvation stems from unfair scheduling policies, thread priority abuse, greedy lock acquisition patterns, and monopolization of shared resources—all scenarios where some threads consistently win while others consistently lose.