Chapter

10

Fairness, derived

Part III · Time

  • 5 lessons
  • 3 h 37 min of core lessons
  • Skills: hostile-env, intent, evidence

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.cfg split.
  • 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, TaskBoard in 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-ai1 to 10-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:

shell
./tla check 10-01
./tla check 10-review
./tla check --gate 10

Skills

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 10

    Hints

    Hint 1

    Write TypeOK, Init, Submit, Finish, GoOffline and GoOnline first, with the cfg, and run it after each. Then Grant and Skip, 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. Write Liveness before any fairness, and watch it fail.

    Hint 2

    Run Liveness with 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")

    Safety relates two variables, printing and turn, and only matters while something is printing. Liveness is about every desk, and about waiting and printing; 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 --twin

    Hints

    Hint 1

    Write TypeOK, Init, Arrive, Unplug, PowerCut and PowerBack first, with the cfg, and run it after each. Then Plug and Pass, 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. Write Liveness before any fairness, and watch it fail.

    Hint 2

    Run Liveness with 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")

    Safety relates two variables, charging and turn, and only matters while something is charging. Liveness is about every bay, and about queued and charging; 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.