Peterson's Bounded-State Filter Lock and Single-Register Impossibility #
This module pairs two foundational results on shared-memory mutual exclusion over atomic read/write
registers, complementing the unbounded-ticket safe-register Bakery algorithm in Bakery.lean:
Peterson's
(n - 1)-Leveln-Process Filter Lock (filterLock, [Pet81], Fig. 3, p. 116): Using bounded0-indexedFin n-valued atomic read/write arrayslevel : Fin n → Fin nandvictim : Fin (n - 1) → Fin n(evaluating each waiting room's test via single-register readscheckVictimandcheckLevelwithout multi-word snapshots or read-modify-write primitives), each waiting roomr : Fin (n - 1)acts as a filter admitting at mostn - (r + 1)processes (card_at_level_le, proof infrastructure for Fig. 3). At the final levelℓ = n - 1, capacityn - (n - 1) = 1yields mutual exclusion (filterLock_mutualExclusion). Inspecting the highest occupied waiting room (filterLock_step_progress) yields an enabled finite trying-only execution reachingCriticalSection(filterLock_exists_cs_execution, a finite progress witness; fair-execution progress across infinite runs with a sequenced room scan remains open in #7296).Single-Register Covering-Write Impossibility Step (
not_deadlockFreeMutex_of_single_register, 1-register base step toward [BL93], Theorem 5.1, p. 177): Formalizes deterministic asynchronous multi-writer atomic read/write register protocols (MutexProtocol P Reg Val State, with.remainder,.trying,.cs, and.exitregions inMutexSection). HereMutexProtocol.DeadlockFreeasks for some process to reach.csfrom an initially trying state underMutexProtocol.WeakFair(scheduling.tryingand.exit) andMutexProtocol.CSEventuallyExits, whereas [BL93] (§§2–3, pp. 173–175) asks for a region change in each nonnull fair history. Proves theFintype.card Reg ≤ 1(2 ≤ Fintype.card P) step via one blind write overwriting another process's writes (specializing Lemma 5.2's indistinguishability replay and Lemma 5.4's covering-write argument, pp. 177, 180); the fullFintype.card P ≤ Fintype.card Regbound stays open under #7296.
Main definitions #
Cslib.Distributed.MutualExclusion.FilterPhase: per-process control state of Peterson'sn-thread filter lock.Cslib.Distributed.MutualExclusion.FilterState: global state(phase, level, victim)overFin n-valued registers, withinit,inCS,isTrying,atLevel,potential, andReachable.Cslib.Distributed.MutualExclusion.FilterAction: single-register atomic read/write actions of the filter lock.Cslib.Distributed.MutualExclusion.filterStep?,Cslib.Distributed.MutualExclusion.filterStepTrace?: computable single-step and trace evaluators.Cslib.Distributed.MutualExclusion.filterLock: theCslib.LTSof Peterson'sn-process filter lock.Cslib.Distributed.MutualExclusion.MutexSection,Cslib.Distributed.MutualExclusion.RegStep,Cslib.Distributed.MutualExclusion.MutexProtocol,Cslib.Distributed.MutualExclusion.MutexConfig,Cslib.Distributed.MutualExclusion.MutexAction: general deterministic asynchronous atomic read/write register mutual-exclusion protocols and theirCslib.LTSsemantics (MutuallyExclusive,WeakFair,CSEventuallyExits,DeadlockFree,DeadlockFreeMutex).
Main results #
Cslib.Distributed.MutualExclusion.filterLock_mutualExclusion: Mutual Exclusion for Peterson's Fig. 3n-process filter lock ([Pet81], p. 116) — in every reachable state offilterLock n, at most one process is inCriticalSection(proved via the level-capacity infrastructureatLevel_level_geandcard_at_level_le).Cslib.Distributed.MutualExclusion.filterLock_exists_cs_execution: Finite Progress Witness forfilterLock— from any reachable state with a nonempty set of trying processes, there exists an enabled finite trying-only execution reachingCriticalSection(built on single-step potential infrastructurefilterLock_step_progress, without claiming fair-execution liveness; see #7296).Cslib.Distributed.MutualExclusion.not_deadlockFreeMutex_of_single_register: Single-Register Impossibility Step toward [BL93], Theorem 5.1 (#7296) — for2 ≤ Fintype.card PandFintype.card Reg ≤ 1, noMutexProtocol P Reg Val StateachievesDeadlockFreeMutex.
References #
Part 1: Peterson's bounded-state n-process Filter Lock #
Per-process control phase of Peterson's n-process filter lock [Pet81].
- remainder {n : ℕ} : FilterPhase n
Noncritical remainder section (
level[p] = 0). - ready {n : ℕ} (ℓ : Fin n) : FilterPhase n
- writeVictim {n : ℕ} (r : Fin (n - 1)) : FilterPhase n
Poised to write
victim[r] := pafter settinglevel[p] := r + 1. - waitRoom {n : ℕ} (r : Fin (n - 1)) (cleared : Finset (Fin n)) : FilterPhase n
Waiting in room
r(level[p] = r + 1), having confirmedlevel[q] < r + 1for eachq ∈ cleared. - cs {n : ℕ} : FilterPhase n
Critical section (
CS).
Process has strictly passed waiting room r and has not exited .cs.
Bounded local progress rank of a FilterPhase n.
Global configuration of Peterson's n-process filter lock over bounded Fin n registers.
- phase : Fin n → FilterPhase n
Per-process control phase.
Initial quiescent configuration with all processes in .remainder and all registers 0.
Process p is in its critical section (CS).
Instances For
Process p is in its trying section.
Instances For
Processes that have reached filtered level ℓ (0 ≤ ℓ < n) and passed all wait rooms < ℓ.
Global progress potential summing FilterPhase.potential across all n processes.
Single-register atomic actions of Peterson's n-process filter lock.
- requestCS {n : ℕ} (p : Fin n) : FilterAction n
Process
pleaves.remainderto acquire the lock. - enterCSOne {n : ℕ} (p : Fin n) : FilterAction n
- setLevel {n : ℕ} (p : Fin n) : FilterAction n
Process
patomically writeslevel[p] := ℓ + 1to enter waiting roomℓ. - setVictim {n : ℕ} (p : Fin n) : FilterAction n
Process
patomically writesvictim[r] := pin waiting roomr. - checkVictim {n : ℕ} (p : Fin n) : FilterAction n
Process
patomically readsvictim[r]in roomr(advancing ifvictim[r] ≠ p). - checkLevel {n : ℕ} (p q : Fin n) : FilterAction n
Process
patomically readslevel[q](q ≠ p) in roomr. - exitCS {n : ℕ} (p : Fin n) : FilterAction n
Process
pexits.cs, atomically resettinglevel[p] := 0.
Acting process of a FilterAction.
Computable single-step transition evaluator for Peterson's filter lock.
Computable multi-step trace evaluator for filterStep?.
Labelled transition system of Peterson's n-process filter lock [Pet81].
A FilterState is reachable if it is reachable from FilterState.init n in filterLock n.
Filter lock inductive invariants, capacity bound, mutual exclusion, and deadlock freedom #
Inductive level-capacity invariant (proof infrastructure for Peterson's Fig. 3 protocol,
[Pet81], p. 116): in every reachable state of filterLock n, for every level ℓ < n, at
most n - ℓ processes belong to s.atLevel ℓ (having reached level ≥ ℓ and passed all waiting
rooms < ℓ).
Mutual Exclusion for Peterson's Filter Lock ([Pet81], Fig. 3, p. 116): in every
reachable state of filterLock n, at most one process is in CriticalSection.
Deadlock freedom of Peterson's filter lock #
Single-step potential-progress lemma (proof infrastructure for
filterLock_exists_cs_execution): in any reachable state where the set of trying processes is
nonempty and no process is in CriticalSection, some trying process has an enabled step (advancing
from .ready/.writeVictim, passing the highest occupied waiting room r_max when not
victim[r_max], or recording a lower-level witness at r_max when it is the unique occupant) that
strictly increases FilterState.potential without waking any remainder process.
Finite Progress Witness for filterLock: from any reachable state where at least one
process is trying (∃ p, s.isTrying p), there exists an enabled finite execution stepping only
trying processes (never waking .remainder processes or exiting .cs) that reaches a state with a
process in CriticalSection.
This provides an existential finite execution witness (which may schedule several trying
processes, can be empty if some process is already in .cs, and only promises that some process is
in .cs at the end), rather than progress across all fair infinite executions (OmegaExecution),
which requires sequencing the waiting-room scan (#7296).
Part 2: General Multi-Writer Register Mutex Protocols & Single-Register Impossibility #
Standard four-phase section partition of a shared-memory mutual-exclusion process.
- remainder : MutexSection
Noncritical remainder section.
- trying : MutexSection
Entry / doorway / waiting section trying to enter
cs. - cs : MutexSection
Critical section (
CS). - exit : MutexSection
Exit protocol resetting shared variables before returning to
remainder.
Elementary atomic step of a process over multi-writer atomic read/write registers Reg with
value domain Val (no read-modify-write primitives).
- localStep {Reg : Type u_1} {Val : Type u_2} {State : Type u_3} (next : State) : RegStep Reg Val State
Internal local transition neither reading nor writing shared memory.
- read {Reg : Type u_1} {Val : Type u_2} {State : Type u_3} (r : Reg) (cont : Val → State) : RegStep Reg Val State
Atomic read of shared register
r, branching tocont von observed valuev. - write {Reg : Type u_1} {Val : Type u_2} {State : Type u_3} (r : Reg) (val : Val) (next : State) : RegStep Reg Val State
Atomic blind write
r := val, transitioning to local statenext.
General deterministic asynchronous mutual-exclusion protocol over processes P, atomic
multi-writer read/write registers Reg with values in Val, and local process states State.
- initMem : Reg → Val
Initial contents of shared registers.
- initLocal : P → State
Initial local state of each process.
- sectionOf : P → State → MutexSection
- enterTrying : P → State → State
Invocation transition when
pleaves.remainderto acquire the lock. - step : P → State → RegStep Reg Val State
- exitCS : P → State → State
Every process starts in
.remainder.- enterTrying_section (p : P) (st : State) : self.sectionOf p st = MutexSection.remainder → self.sectionOf p (self.enterTrying p st) = MutexSection.trying ∨ self.sectionOf p (self.enterTrying p st) = MutexSection.cs
- trying_step_section (p : P) (st : State) : self.sectionOf p st = MutexSection.trying → ∀ (st' : State), (self.step p st).NextState st' → self.sectionOf p st' = MutexSection.trying ∨ self.sectionOf p st' = MutexSection.cs
Global configuration of a MutexProtocol: shared register memory and local process states.
- mem : Reg → Val
Shared register contents.
- localState : P → State
Local state of each process.
Transition labels of a MutexProtocol LTS.
- enter {P : Type u_1} (p : P) : MutexAction P
Process
pleaves.remainderviaenterTrying. - step {P : Type u_1} (p : P) : MutexAction P
- exit {P : Type u_1} (p : P) : MutexAction P
- stutter {P : Type u_1} : MutexAction P
Stuttering step preserving the configuration.
Process p is in its critical section under π.
Instances For
Process p is in its trying section under π.
Instances For
Process p has an active protocol step enabled (.trying or .exit).
Instances For
Initial configuration (initMem, initLocal) of π.
Execute p's atomic RegStep on configuration c.
Computable single-step transition evaluator for π.
Computable multi-step trace evaluator for π.step?.
Labelled transition system of π.
Reachability from π.initConfig in π.lts.
Mutual Exclusion: in every reachable configuration, at most one process is in .cs.
Weak step fairness for active processes (.trying or .exit); processes in .remainder may
remain quiescent indefinitely.
Deadlock Freedom (critical-section entry from an initially trying state): in every infinite
execution from a reachable configuration with at least one trying process, assuming WeakFair
(scheduling active processes in .trying or .exit) and CSEventuallyExits, some process
eventually reaches .cs (∃ k q, (ss k).inCS π q).
Whereas [BL93] (§3, pp. 174–175) defines global progress as some process changing regions
in each nonnull fair history (stepping every process outside .remainder), this predicate asks for
some process to reach .cs from an initially trying state under WeakFair and
CSEventuallyExits.
Combined specification: π achieves both MutuallyExclusive and DeadlockFree.
Covering-write proof of the single-register impossibility step #
Intermediate 1-register covering-write base step toward the Fintype.card P ≤ Fintype.card Reg
space lower bound of [BL93] (Theorem 5.1, p. 177; tracked in #7296): for
2 ≤ Fintype.card P processes and Fintype.card Reg ≤ 1 atomic multi-writer read/write registers,
no deterministic asynchronous MutexProtocol satisfies DeadlockFreeMutex (MutuallyExclusive and
DeadlockFree).
Here MutexProtocol includes .remainder, .trying, .cs, and .exit (MutexSection), and
MutexProtocol.DeadlockFree asks for some process to reach .cs from an initially trying state
under MutexProtocol.WeakFair (scheduling .trying and .exit) and
MutexProtocol.CSEventuallyExits, whereas [BL93] (§§2–3, pp. 173–175) asks for a region
change in each nonnull fair history. The proof uses one poised blind write to erase the second
process's writes, specializing the indistinguishability and covering-write arguments of
[BL93], Lemmas 5.2 and 5.4 (pp. 177, 180).