Resource starvation is a condition in concurrency where a thread, process or request is ready to make progress but is repeatedly denied the CPU time, lock, memory or other resource it needs, because other contenders keep receiving it first. Unlike a deadlock, the system as a whole keeps working; only the starved task stalls, sometimes indefinitely.
In programming, starvation is also called thread starvation when the victim is a thread, and it violates the liveness property known as bounded waiting: the guarantee that every request is eventually served within a finite number of turns.
How resource starvation arises
Starvation results from an allocation policy that is not fair, combined with sustained demand from other contenders. A scheduler or lock that always picks the highest priority, the newest arrival or simply the fastest thread can leave a slower contender waiting forever, even though the resource becomes free many times.
Three ingredients are usually present. First, there is contention: more requesters than the resource can serve at once. Second, the selection rule has no aging or ordering guarantee. Third, the favored group generates continuous demand, so the gap the victim needs never appears. Remove any one of these and starvation usually disappears.
The table below lists the resources that are most often starved and how the symptom typically appears.
| Resource | Typical cause | Visible symptom |
|---|---|---|
| CPU time | Strict priority scheduling | Low-priority jobs never finish |
| Mutex or monitor | Unfair lock barging | One thread waits while others re-acquire |
| Read-write lock | Continuous stream of readers | Writers never obtain the lock |
| Thread pool worker | Long or blocking tasks fill the pool | Queued tasks time out |
| Connection pool | Leaked or long-held connections | Requests wait for a free connection |
| Network or disk bandwidth | One heavy flow dominates | Latency spikes for small flows |
Starvation compared with deadlock and livelock
Starvation, deadlock and livelock are all liveness failures, but they differ in who is affected and whether anything progresses. In a deadlock, a cycle of tasks each holds what another needs, so all of them stop. In a livelock, tasks keep changing state in response to one another without completing work. In starvation, the system progresses but an individual task does not.
| Failure | System progress | Affected tasks | Typical remedy |
|---|---|---|---|
| Resource starvation | Yes | One or a few | Fair queuing, aging |
| Deadlock | No, for involved tasks | All tasks in the cycle | Lock ordering, timeouts |
| Livelock | No useful work | All interacting tasks | Randomized backoff |
| Priority inversion | Partial | High-priority task | Priority inheritance |
Priority inversion is closely related: a high-priority task waits for a lock held by a low-priority task, which is itself starved of CPU by medium-priority work. The result is that the most important task is effectively starved, which is why real-time systems implement priority inheritance.
Scheduling and locking patterns that cause starvation
Most cases of starvation can be traced to a small set of recurring patterns. Recognizing them during design review is much cheaper than diagnosing a production stall.
- Strict priority scheduling without aging lets high-priority work monopolize the processor.
- Reader-preferring read-write locks allow overlapping readers to block writers indefinitely.
- Barging locks, where a releasing thread can immediately re-acquire, favor threads already running on a CPU.
- Shortest-job-first policies can postpone long jobs forever under continuous short arrivals.
- Spinlocks on contended cores favor the thread with better cache locality.
- Bounded thread pools with blocking tasks let dependent tasks wait for workers that never free up.
The last pattern deserves attention in asynchronous programming. When every worker in a pool blocks on a result that must be computed by another task queued in the same exhausted pool, the queued task is starved, and the symptom can resemble a deadlock even though no lock cycle exists.
Preventing and mitigating starvation
Prevention means guaranteeing bounded waiting through the allocation policy, not hoping that load stays low. The appropriate technique depends on which resource is contended and how much throughput the system can trade for fairness.
| Technique | How it works | Trade-off |
|---|---|---|
| Aging | Raises the priority of tasks the longer they wait | Adds scheduler bookkeeping |
| Fair locks | Grant ownership in FIFO order | Lower throughput under contention |
| Writer-preferring locks | Block new readers once a writer waits | Can starve readers instead |
| Ticket locks | Serve requests by issued ticket number | Poor scaling on many cores |
| Separate thread pools | Isolate blocking or dependent work | More threads to tune |
| Weighted fair queuing | Share capacity by assigned weights | Requires weight configuration |
Fairness has a cost. A strictly fair lock forces a context switch to the next waiter instead of letting the running thread continue, which can reduce throughput substantially under heavy contention. Many runtimes therefore default to unfair but fast locks and offer a fair variant, such as the fairness flag of Java’s ReentrantLock, for cases where bounded waiting matters more than raw speed.
Detecting starvation in running systems
Starvation is hard to detect because averages look healthy while a minority of tasks wait. Monitoring should therefore focus on tail behavior and per-task waiting time rather than mean throughput.
| Signal | What it suggests | Next diagnostic step |
|---|---|---|
| Rising p99 latency, stable median | A subset of requests waits too long | Break latency down by request class |
| Growing queue length | Workers never reach queued tasks | Inspect pool saturation and blocking calls |
| Threads stuck in waiting state | Lock acquisition never succeeds | Take thread dumps over time |
| Watchdog or timeout alarms | Tasks exceed bounded waiting | Correlate with lock hold times |
A practical rule is to record how long each request waits for a lock, a worker or a connection, and to alert on the maximum, not the average. Repeated thread dumps that show the same thread waiting while others cycle through the lock are strong evidence of lock-level starvation.
The idea in brief
Resource starvation is like standing at a busy counter where the clerk always serves whoever shouts loudest. The shop stays busy and many customers leave happy, but one quiet customer may never be served.
In a computer, many tasks share processors, locks and connections. If the rules for sharing always favor certain tasks, others can wait without end. The fix is to add a fair rule, such as taking turns or giving extra priority to anyone who has waited too long.
A practical scenario
An inventory service caches product data behind a reader-preferring read-write lock. During a sales event, about 4,000 read requests per second keep at least one reader inside the lock at all times. A background job that applies price updates needs the write lock, but it waits for more than 40 minutes, so customers see outdated prices even though every server reports normal CPU use.
Engineers notice that the median read latency is fine while the update job never completes. Thread dumps show the writer blocked on the same lock in every sample. The team switches to a writer-preferring lock policy, which blocks new readers as soon as a writer is waiting, and adds an alert on maximum lock wait time. Price updates now finish within a few hundred milliseconds, with only a small increase in read latency during each update.