Definition
Starvation is a situation in which a thread, task or request that is ready to make progress is denied a resource it needs, such as processor time, a lock or a place in a queue, for an unbounded time, because the rule that hands out the resource keeps choosing others. The rest of the system keeps working. That separates starvation from deadlock §9.14, in which the threads involved wait for each other and none progresses. Starvation is also called indefinite postponement.
The idea
A maintenance task, for example one that compacts a log, has the lowest priority, and a strict priority scheduler always runs the highest-priority ready task. As long as higher-priority work is ready at every moment, the maintenance task never runs. Each scheduling decision is correct on its own; the problem lies in the sequence of decisions. Nothing is stuck, every other task completes and the processor is fully busy, so the system looks healthy while one task waits forever.
A hospital emergency department is a fair picture. Triage treats the most serious case first, which is right for each decision, yet a patient with a sprained ankle can wait all night if ambulances keep arriving. A remedy in the same spirit is to let waiting time itself raise a patient’s place in line; schedulers call that aging. The picture stops being exact in one respect: a patient can give up and leave, while a starving thread just waits.
How it works
Starvation always involves a resource and a rule for granting it. Name both. The common cases are:
Processor time under strict priorities: a ready low-priority task never runs while higher-priority demand fills the processor.
A lock that does not queue its waiters: when the holder releases the lock and at once requests it again, it can win again before a woken waiter runs, every time. A readers–writer lock, which admits many readers at once or one writer, starves writers if it keeps admitting new readers while a writer waits and the readers overlap.
Retry loops: in a lock-free §9.13 algorithm §14.1, one thread can lose every race on compare-and-swap §9.9, an atomic instruction that replaces a value only if it still equals an expected one, while others win.
Queue policies: a queue that always serves the shortest job, or the highest-priority request, can postpone a long or low-priority request forever.
The remedies change the rule for granting the resource:
Aging: raise a waiting task’s priority with the time it has waited, until it outranks the work that keeps passing it.
Arrival order: serve waiters first come, first served. A ticket lock gives each arriving thread a number and grants the lock in number order, so each waiter waits only for the threads that arrived before it.
Reserved share: guarantee the low-priority work a budget, such as 2 ms in every 20 ms, or run tasks of equal priority round-robin, giving each a time slice in turn.
Bounded demand: limit how much high-priority work is admitted, for example by rate limiting §9.38, which caps how often new work is accepted, so that it cannot fill the processor.
Stronger guarantees: replace a lock-free algorithm by a wait-free one, or a reader-preferring lock by one that stops admitting new readers while a writer waits.
Each remedy costs something: aging and budgets delay urgent work a little, and arrival order ignores urgency.
Worked example
One processor; ignore the time the scheduler itself takes. A high-priority job is released every 1 ms, at times 0, 1, 2 ms and so on, and each job needs 1 ms of processor time. Job 1 runs from 0 to 1 ms, job 2 from 1 to 2 ms, and so on. The share of the processor that these jobs use, their utilization, is execution time §9.32 divided by period: , that is 100%. A ready maintenance task of lower priority gets 0 ms in every millisecond. It starves for as long as the jobs keep coming.
Now let each job need 0.6 ms. The utilization is , so ms of every 1 ms is left. In the period that starts at ms, for each whole number , the job runs from to ms and the maintenance task from to ms. If maintenance needs 10 ms of processor time in all, it needs periods, so it finishes at 25 ms: 10 ms of its own execution spread over 25 ms. Spare capacity removed the starvation, and this release pattern gave a definite finishing time.
Starvation at a lock: readers arrive every 2 ms, at 0, 2, 4 ms and so on, and each holds a read lock for 3 ms. Reader number , counting from 0, holds the lock from to ms, and the next reader arrives at ms, 1 ms before reader leaves. At every moment at least one reader holds the lock. A writer needs the lock with no reader inside. Under a reader-preferring rule new readers keep entering while the writer waits, so the writer never gets in, although the lock is in use the whole time.
Stated precisely
Two standard properties rule starvation out.
Starvation-freedom: every thread that requests the resource eventually receives it, provided that every holder eventually releases it.
Bounded waiting: there is a number such that, after a thread requests the resource, the resource is granted to other threads at most times before it is granted to that thread. A first-come, first-served lock shared by threads has .
Starvation-freedom is a liveness property §1.12, a requirement that something good eventually happens, and it gives no time bound. Bounded waiting counts grants, not time; a time bound needs, in addition, the longest time each grant can last. For processor time, the matching property of a scheduler is weak fairness: a task that is ready without interruption from some moment on eventually runs. Strict fixed-priority scheduling is not weakly fair to its lowest-priority task, as the first example shows.
For fixed-priority scheduling on one processor, let the higher-priority tasks have execution times and shortest release intervals , and let be their total utilization. If , the higher-priority tasks can keep the processor busy forever, and the lowest-priority task can starve. If , task is released at most times in any interval of length , so the higher-priority work released in that interval is at most . Counting from system start, when no work is pending, the processor time left for the lowest-priority task by time is therefore at least , which grows without limit, so that task cannot starve. How soon it finishes is a separate question, answered by a response-time analysis that also counts blocking.
Limits and common mistakes
A busy, productive system can still starve one task. High throughput says nothing about fair service.
Starvation is not deadlock. No threads are blocked in a cycle, and the starving task would run at once if the competing demand paused.
A fair scheduler or a fair lock promises eventual service, not a deadline. State fairness as a property: for which requests, for which resource, and whether the bound counts grants or time.
Fixing starvation at one resource does not fix it at the next. A task with a guaranteed processor share can still starve at a lock or in a queue, so check every resource the task needs.
Priority inheritance §9.17 does not prevent starvation. It helps a waiting high-priority task, not a low-priority one.
Aging needs a limit. Unlimited aging can raise maintenance above truly urgent work and make that work miss its deadlines, so the raised priority needs a cap below the most urgent work.
A watchdog timer §6.16, a hardware timer that resets the processor unless software restarts it regularly, turns silent starvation of the task that restarts it into a visible reset. That detects starvation; it does not prevent it.
Questions answered
Can repeated high-priority work indefinitely postpone a maintenance task?
Yes, repeated high-priority work can postpone a maintenance task indefinitely. Under strict priority scheduling, the scheduler always runs the highest-priority ready task, so a lower-priority maintenance task runs only when no higher-priority work is ready. If higher-priority work arrives fast enough to keep the processor busy all the time, for example jobs that each need 1 ms and are released every 1 ms, the maintenance task stays ready forever and never runs, although nothing is deadlocked and every other job completes.
To rule this out, bound the higher-priority demand so that its utilization, the sum over tasks of execution time divided by period, is below 1, and then compute the maintenance task’s worst-case response time. Alternatively, reserve a budget for maintenance, such as a fixed slice of every period, or raise its priority as it waits, which is called aging. A watchdog that the maintenance task must service detects starvation but does not prevent it.
Related entries: Lock-free versus wait-free (§9.13), Schedulability (§9.37), Backpressure (§9.30), Liveness property (§1.12), Rate limiting (§9.38).