Definition
A liveness property is a property of a system’s executions that says something good eventually happens: every request eventually gets a response, or a program eventually terminates. No finite observation refutes a liveness property, because whatever has happened so far, the good thing can still happen later. Proving one needs assumptions about the environment, above all fairness: a guarantee that the scheduler, the part of the system that decides what runs next, does not postpone a ready action forever.
The idea
A request waits in a queue. Nothing forbidden has happened: no memory was corrupted and no rule was broken. Yet the user who sent the request still has no answer. A system that does nothing at all breaks no safety property §1.11, a rule that something bad never happens, so safety alone allows a system that is safe and useless. A liveness property rules that out by demanding progress.
Progress depends on parts that the program does not control. A worker thread, one of several instruction sequences that take turns on the processor, finishes a request only if the scheduler lets it run, every lock it needs is eventually released by whoever holds it, every function it calls returns, and every device it waits for answers. A lock is a flag that lets only one thread at a time use some shared data. A correct loop inside the worker guarantees nothing if the worker is never scheduled. So a liveness claim always comes with a list of assumptions about the scheduler, the other threads, the network and the hardware, and the claim is only as good as that list.
A queue at a counter is a fair picture. The promise “everyone in the queue is eventually served” needs the clerk to keep working and to take people in a fair order. The picture also shows the limit of the promise: it says eventually, not soon. A clerk who serves one person a year, in order of arrival, still keeps the promise.
How it works
A liveness claim is shown in four steps.
State the trigger and the good event. For example: whenever a request is admitted, a response to that request follows at some later step.
List every step that progress needs. For a request: the worker is scheduled, acquires each lock it needs, gets an answer from each call and device, and reaches the step that sends the response.
State the environment assumptions. Every lock holder eventually releases the lock; every called operation eventually returns; the sensor eventually answers; messages sent over the network are eventually delivered; the scheduler is fair.
Show that the assumptions force progress. A common method is a ranking function §3.25: a whole number, computed from the state, that is never negative, never increases, and decreases at every step of progress. An example is the number of requests ahead in the queue. The fairness assumption guarantees that steps of progress keep happening, and a whole number that is never negative cannot decrease forever, so the good event must come.
Fairness assumptions come in two standard strengths. An action is enabled in a state when it could run in that state.
Weak fairness: an action that stays enabled continuously from some point on is eventually taken. It forbids a scheduler from ignoring a thread that is ready all the time.
Strong fairness: an action that is enabled infinitely often, even with pauses in between, is eventually taken. It also forbids a scheduler that picks a thread only at moments when that thread cannot run.
Strong fairness implies weak fairness. Neither gives a number: both say eventually, not within how long.
Worked example
Two tasks share one processor: a worker W that answers requests and a background task B. Both are always ready to run. The schedule B, B, B, and so on forever, gives W no time, and no response is ever sent. Weak fairness rules this schedule out, because W stays enabled continuously and is never taken.
Now let W also need a lock that B takes and releases over and over, so W is enabled only while the lock is free. A scheduler that gives the processor to B at every moment when the lock is free never runs W. W is not continuously enabled, so weak fairness does not forbid this schedule. W is enabled infinitely often, so strong fairness does.
Fairness says nothing about speed. A schedule that runs B one million times, then W once, and repeats, satisfies both kinds of fairness. If each run of B takes 10 microseconds, W waits microseconds, which is 10 seconds, between turns. Against a 10-millisecond response requirement that is a miss by a factor of , while the liveness property still holds. A bounded response time §9.32 needs a quantitative scheduling analysis, built on the worst-case execution time §9.33 of each task, the longest time it can take to run, and not a fairness assumption.
A timeout §9.34 does not create progress by itself. A helper thread waits for a sensor that never answers. A counter in the caller that gives up after 100 polls ends the caller’s wait, but the helper is still stuck and still holds whatever it took. The timeout helps only if it can stop or contain the stuck operation and return what that operation held.
Stated precisely
Let an execution be an infinite sequence of states , and let a property be the set of executions that satisfy it. is a liveness property when every finite sequence of states can be extended to an execution in : where means followed by . So no finite prefix is ever a proof of violation. Bowen Alpern and Fred Schneider gave this definition in 1985 [235] and proved that every property is the intersection of a safety property and a liveness property. Total correctness of a program is a familiar case: partial correctness, a right result if the program stops, is the safety part, and termination is the liveness part.
The response property in this form reads: for every position at which a request is admitted, there is a later position at which its response is sent. Seeing 100 steps without a response refutes nothing, because the response may come at step 101. The bounded version, “a response within 100 steps”, is refuted at step if no response has come, so it is a safety property. The two promises need different evidence: the first a proof under fairness assumptions, the second a bound on every path.
A liveness proof names its assumptions. The usual ones are: the scheduler is weakly or strongly fair to the actions that make progress; every lock holder releases the lock after finitely many steps; every called operation returns after finitely many steps; every message sent is eventually delivered; and no component that progress needs fails permanently.
Limits and common mistakes
Freedom from deadlock §9.14, a state in which each thread of a group waits for another thread of the group so that none can proceed, is weaker than liveness for each request. A system without deadlock can keep doing other work forever while one request suffers starvation §9.18: it waits without end while others proceed.
Livelock breaks liveness too. The threads keep running, for example by retrying in lockstep after each collision, but none of them gets anywhere.
Real schedulers are often not fair. A fixed-priority preemptive scheduler always runs the highest-priority thread that is ready, so a high-priority thread that never blocks starves every lower-priority one. A liveness proof that assumes fairness applies to such a scheduler only if the high-priority work is bounded.
A successful run shows that progress is possible, not that it is forced. A test in which every request was answered does not show that every schedule answers them.
Liveness is not timeliness. “Eventually” allows any finite delay. Real-time requirements are bounded-response properties, and those are safety properties.
Some liveness goals are impossible without extra assumptions. Michael Fischer, Nancy Lynch and Michael Paterson proved in 1985 [232] that in an asynchronous system, where messages may be delayed for any finite time, no deterministic protocol for consensus, meaning agreement of several processes on one value, can guarantee termination if even one process may crash. The result is known as FLP, after the initials of Fischer, Lynch and Paterson. Practical protocols regain liveness by assuming that delays eventually become bounded, or by using randomness.
Questions answered
What fairness or scheduling assumptions make progress possible?
Progress needs assumptions that every step on the path to the good event eventually gets to run and eventually finishes. The usual ones are:
a fair scheduler: weak fairness, meaning that an action that stays ready to run is eventually run, or strong fairness, meaning that an action that becomes ready again and again, even with pauses, is eventually run;
finite holding of shared resources: every thread that holds a lock or another shared resource releases it after finitely many steps, and the lock itself hands out access fairly, so that a waiting thread is not overtaken forever;
finite blocking: every function or device call on the path returns after finitely many steps, or is cut off by a timeout that really frees what the call held;
eventual delivery: the messages and hardware events that the path waits for eventually arrive;
no permanent failure of a component that progress needs.
Under these assumptions, a liveness proof shows that every allowed schedule reaches the good event, usually with a quantity that decreases at each step of progress. A fixed-priority scheduler is not fair by itself: progress for low-priority work also needs a bound on how much processor time the higher-priority work takes. None of these assumptions bounds the waiting time; a deadline needs a quantitative scheduling analysis.
Related entries: Availability (§1.10), Ranking function (§3.25), Schedulability (§9.37), Safety property (§1.11), Deadlock (§9.14), Starvation (§9.18), Worst-case execution time (WCET) (§9.33). Further reading: [232, 235].