Chapter
10
Fairness, derived
Part III · Time
Lessons
About
You are the scheduler, and you are hostile. Two processes share a lock. Starve process B for ever.
You will manage it, more than once. Each time you win, you find one cheat, and the course takes that cheat away with a single conjunct. Write the conjuncts down and you have weak fairness and strong fairness, derived from your own counterexamples instead of handed to you as definitions. Then the chapter turns round. Fairness is an assumption about the world, and an assumption that is too strong makes a broken design pass. So the last two lessons ask what fairness can hide, and what real mechanism, if any, keeps each promise.
Before you start
- Chapter 09: liveness,
~>, lassos, and the.live.cfgsplit. - Chapters 04 and 06:
<<A>>_v, and processes that interleave. - On the essentials track: 10-05 writes fairness on PlusCal processes (
fair,fair+) and reads their translation. Read the recaps of 04-03, 07-01 and 07-02 (chapters/04-stuttering/CONCEPTS.md,chapters/07-pluscal/CONCEPTS.md) before that lesson. - Time: the chapter page shows the estimate, generated from the lessons.
What else is here
specs/:FairLock,Elevator,DiningPhilosophers,TaskBoardin TLA+ and in PlusCal, and the one-change variants the lessons run.review/(10-review): a mail relay with one quantifier in the wrong place.ai/(10-ai1to10-ai3): a single-track railway, a two-priority scheduler and a queue lock, each with an assistant's claim to judge.gate/(10-gate): round-robin printer arbitration;gate/twin/(10-gate-twin): a shared charging station. The skeletons supply the interface only.
Run it
From the repository root:
./tla check 10-01
./tla check 10-review
./tla check --gate 10Skills
hostile-env (modelling a hostile environment), intent (stating intent as properties), evidence (knowing what a check covers).
Elsewhere
- Web version: https://indicogni.com/learn/tla-plus/10-fairness/
- Recaps:
CONCEPTS.md. Hints and explanation checks:HINTS.md. Predictions without answers:PREDICT.md. - Solutions:
solutions/chapters/10-fairness/, including the gate references and their mutants. - Further reading: the dining philosophers problem was first published in Edsger W. Dijkstra's 1971 paper Hierarchical ordering of sequential processes. Two flags and a turn (
10-mx) is Gary L. Peterson's 1981 mutual-exclusion algorithm (Myths About the Mutual Exclusion Problem, Information Processing Letters 12(3)). Both models and their names are the course's own.
Beyond the lessons
- 10-review Review a teammate’s spec ·
chapters/10-fairness/review/·./tla check 10-review - 10-ai1 AI item ·
chapters/10-fairness/ai/1-wf-not-sf/·./tla check 10-ai1 - 10-ai2 AI item ·
chapters/10-fairness/ai/2-sf-everywhere/·./tla check 10-ai2 - 10-ai3 AI item ·
chapters/10-fairness/ai/3-correct-fair-lock/·./tla check 10-ai3 - 10-gate Gate ·
./tla check --gate 10Hints
Hint 1
Write
TypeOK,Init,Submit,Finish,GoOfflineandGoOnlinefirst, with the cfg, and run it after each. ThenGrantandSkip, which both need a free printer and differ in whether the desk whose turn it is has a job queued; only one of them also needs the printer online. WriteLivenessbefore any fairness, and watch it fail.Hint 2
Run
Livenesswith no fairness and read the lasso. Then work one lasso at a time: for each action that would end the loop, ask whether it is enabled in every state of the loop, in some, or in none. Every, some and none each point at a different answer, and lesson 10-03's IN YOUR EDITOR says which. Add one conjunct, rerun, and read the next lasso.Hint 3 (nearly the answer; opening it marks a pass as "passed with help")
Safetyrelates two variables,printingandturn, and only matters while something is printing.Livenessis about every desk, and aboutwaitingandprinting; lesson 10-01's leads-to is the shape. Weak fairness is not enough everywhere: one action is enabled and disabled again by the printer going offline and online, and the printer coming back is infrastructure that needs a promise of its own. - 10-gate-twin Gate twin, another domain ·
./tla check --gate 10 --twinHints
Hint 1
Write
TypeOK,Init,Arrive,Unplug,PowerCutandPowerBackfirst, with the cfg, and run it after each. ThenPlugandPass, which both need a free charger and differ in whether the car whose turn it is is asking; only one of them also needs power. WriteLivenessbefore any fairness, and watch it fail.Hint 2
Run
Livenesswith no fairness and read the lasso. Then work one lasso at a time: for each action that would end the loop, ask whether it is enabled in every state of the loop, in some, or in none. Every, some and none each point at a different answer, and lesson 10-03's IN YOUR EDITOR says which. Add one conjunct, rerun, and read the next lasso.Hint 3 (nearly the answer; opening it marks a pass as "passed with help")
Safetyrelates two variables,chargingandturn, and only matters while something is charging.Livenessis about every bay, and aboutqueuedandcharging; lesson 10-01's leads-to is the shape. Weak fairness is not enough everywhere: one action is enabled and disabled again by the power going off and on, and the power coming back is infrastructure that needs a promise of its own.