Section 9.18

Starvation

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:

The remedies change the rule for granting the resource:

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: 1/1=11 / 1 = 1, 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 0.6/1=0.60.6 / 1 = 0.6, so 1−0.6=0.41 - 0.6 = 0.4 ms of every 1 ms is left. In the period that starts at kk ms, for each whole number kk, the job runs from kk to k+0.6k + 0.6 ms and the maintenance task from k+0.6k + 0.6 to k+1k + 1 ms. If maintenance needs 10 ms of processor time in all, it needs 10/0.4=2510 / 0.4 = 25 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 ii, counting from 0, holds the lock from 2i2i to 2i+32i + 3 ms, and the next reader arrives at 2i+22i + 2 ms, 1 ms before reader ii 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 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 CjC_j and shortest release intervals TjT_j, and let U=∑jCj/TjU = \sum_j C_j / T_j be their total utilization. If U≥1U \ge 1, the higher-priority tasks can keep the processor busy forever, and the lowest-priority task can starve. If U<1U < 1, task jj is released at most t/Tj+1t / T_j + 1 times in any interval of length tt, so the higher-priority work released in that interval is at most Ut+∑jCjU t + \sum_j C_j. Counting from system start, when no work is pending, the processor time left for the lowest-priority task by time tt is therefore at least (1−U)t−∑jCj(1 - U) t - \sum_j C_j, 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).