Documentation

CslibFrontier.Computability.Distributed.ConcurrentObjects.TreiberStack

Treiber's Lock-Free CAS Stack (Fresh-Node Step) #

This module formalizes a fresh-node (ABA-free) step toward Treiber's lock-free CAS stack (#7501; after [Tre86]; Hendler, Shavit, and Yerushalmi, §§2.1–2.2, Fig. 2–3, p. 208, §§2.2–2.3, p. 209, and §5, Definition 5.1, Lemma 5.13, and Theorem 5.17, pp. 212–215; Moir and Shavit, §1.3, pp. 1-15–1-16), where each push allocates a fresh node index at heap.length rather than recycling popped nodes through an ABA version-tagged free list.

Both push and pop are modeled as fine-grained multi-step state machines over shared heap nodes and a shared CAS head pointer head : Option ℕ:

Main definitions #

Main results #

References #

Sequential LIFO stack specification #

Operations on a concurrent LIFO stack over element type V.

  • push {V : Type u} (val : V) : StackOp V

    Push val onto the top of the stack.

  • pop {V : Type u} : StackOp V

    Pop and return the top element, or none if the stack is empty.

Responses returned by a concurrent LIFO stack over element type V.

  • pushAck {V : Type u} : StackResp V

    Acknowledge completion of push.

  • popRet {V : Type u} (val : Option V) : StackResp V

    Return some v for the popped top element, or none when the stack was empty.

Deterministic sequential LIFO transition function on List V ([HSY04], §5, Definition 5.1, p. 212).

def Cslib.Distributed.ConcurrentObjects.stackSeqSpec {P : Type u} (V : Type u) :
SeqSpec P (fun (x : Unit) => StackOp V) (fun (x : Unit) => StackResp V) ()

Sequential specification of a LIFO stack over V initialized to [].

Fine-grained multi-step Treiber stack machine (fresh-node model) #

Linked heap node in Treiber's stack holding an element val and next-pointer next.

  • val : V

    Element value stored in this node.

  • next : Option ℕ

    Heap index of the next node down the stack, or none at the bottom.

theorem Cslib.Distributed.ConcurrentObjects.StackNode.ext {V : Type u} {x y : StackNode V} (val : x.val = y.val) (next : x.next = y.next) :
x = y

Fine-grained local execution phase of a thread in the fresh-node Treiber stack (Hendler, Shavit, and Yerushalmi, §2.2, Fig. 3, p. 208).

Global configuration of Treiber's lock-free CAS stack in the fresh-node model: heap stores allocated StackNodes, head holds the optional index of the top node, threads tracks each process's fine-grained control phase, and history records all external invocation and response events observed so far.

  • heap : List (StackNode V)

    Monotonically growing array of allocated stack nodes.

  • head : Option ℕ

    Shared CAS pointer to the current top node (none when empty).

  • threads : P → TreiberPhase V

    Per-process fine-grained execution phase.

  • history : History P (fun (x : Unit) => StackOp V) fun (x : Unit) => StackResp V

    Recorded external concurrent invocation/response history on the stack (Obj = Unit).

theorem Cslib.Distributed.ConcurrentObjects.TreiberFreshNodeState.ext {P V : Type u} {x y : TreiberFreshNodeState P V} (heap : x.heap = y.heap) (head : x.head = y.head) (threads : x.threads = y.threads) (history : x.history = y.history) :
x = y

Initial empty configuration of the fresh-node Treiber stack.

treiberFreshNodeInvoke s p s' holds when idle process p invokes either push v or pop, appending the corresponding invocation event to s.history.

Execute one fine-grained step of active process p in the fresh-node Treiber stack, returning (nextState, completed).

ProgressSystem of Treiber's lock-free CAS stack in the fresh-node model.

Lock-freedom and contention witness (CAS failure implies intervening CAS) #

Fresh-node model step for #7501, not the cited endpoint (after [Tre86]; Hendler, Shavit, and Yerushalmi, §5, Theorem 5.17, p. 215): treiberFreshNodeSystem is lock-free over finitely many processes ([Finite P]), instantiated via ProgressSystem.isLockFree_of_bounded_shared_changes, leaving the ABA version-tagged free-list recycling model open in #7501.

theorem Cslib.Distributed.ConcurrentObjects.treiberFreshNode_cas_fail_witnesses_intervening_cas {P V : Type u} [DecidableEq P] {states : ℕ → TreiberFreshNodeState P V} {labels : ℕ → StepLabel P} {k : ℕ} {p : P} {expected : Option ℕ} (htr : ∀ i < k, (treiberFreshNodeSystem P V).lts.Tr (states i) (labels i) (states (i + 1))) (hread : (states 0).head = expected) (hfail : (states k).head ≠ expected) (hp_no_mod : ∀ i < k, (labels i).proc = p → (states (i + 1)).head = (states i).head) :
∃ (j : ℕ) (q : P) (resp : StackResp V), j < k ∧ q ≠ p ∧ labels j = StepLabel.exec q false ∧ (states (j + 1)).head ≠ (states j).head ∧ (states (j + 1)).threads q = TreiberPhase.returning resp

Fresh-node contention-witness step for #7501, not the cited endpoint (after Hendler, Shavit, and Yerushalmi, §5, Theorem 5.17, p. 215): along any finite execution segment states 0 → ... → states k of treiberFreshNodeSystem, if thread p observed (states 0).head = expected, later encounters (states k).head ≠ expected (causing p's CAS to fail and retry), and did not itself modify head during [0, k), then another thread q ≠ p executed a successful CAS at an intervening step j < k, modifying head and entering .returning resp.

Spine representation and forward inductive invariant for linearizability #

Fresh-node model step for #7501, not the cited endpoint (after [Tre86]; Hendler, Shavit, and Yerushalmi, §5, Lemma 5.13, p. 214): for every reachable configuration s of treiberFreshNodeSystem P V, the recorded concurrent history s.history is linearizable with respect to the sequential LIFO stack specification stackSeqSpec V, leaving the ABA version-tagged free-list recycling model open in #7501.