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 ℕ:
push(v): allocate a fresh heap nodenodeholdingv(pushAlloc), readtop := headand linkheap[node].next := top(pushRead), then executeCAS(&head, top, some node)(pushCAS), retrying frompushReadonCASfailure or enteringreturning .pushAckonCASsuccess before emitting the response event.pop(): readtop := head(popRead); ifhead = none, linearize immediately intoreturning (.popRet none); ifhead = some top, read(val, nxt) := heap[top](popNext) and executeCAS(&head, some top, nxt)(popCAS), retrying frompopReadonCASfailure or enteringreturning (.popRet (some val))onCASsuccess before emitting the response event.
Main definitions #
Cslib.Distributed.ConcurrentObjects.StackOp,Cslib.Distributed.ConcurrentObjects.StackResp,Cslib.Distributed.ConcurrentObjects.stackStep,Cslib.Distributed.ConcurrentObjects.stackSeqSpec: sequential LIFO stack specification overList V(Hendler, Shavit, and Yerushalmi, §5, Definition 5.1, p. 212).Cslib.Distributed.ConcurrentObjects.StackNode,Cslib.Distributed.ConcurrentObjects.TreiberPhase,Cslib.Distributed.ConcurrentObjects.TreiberFreshNodeState: shared heap nodes, fine-grained per-thread control phases, and global fresh-node Treiber stack configurations.Cslib.Distributed.ConcurrentObjects.treiberFreshNodeStep,Cslib.Distributed.ConcurrentObjects.treiberFreshNodeSystem: multi-step operational semantics andProgressSysteminstance for Treiber's stack in the fresh-node model.
Main results #
Cslib.Distributed.ConcurrentObjects.treiberFreshNode_isLinearizable: fresh-node step for #7501 showing every reachable fresh-node Treiber stack configuration has a linearizable concurrent history with respect tostackSeqSpec, with linearization points at successfulpushCAS, emptypopRead, and successfulpopCAS(after Hendler, Shavit, and Yerushalmi, §5, Lemma 5.13, p. 214).Cslib.Distributed.ConcurrentObjects.treiberFreshNode_isLockFree: fresh-node step for #7501 showingtreiberFreshNodeSystemis lock-free over finitely many processes ([Finite P], after Hendler, Shavit, and Yerushalmi, §5, Theorem 5.17, p. 215).Cslib.Distributed.ConcurrentObjects.treiberFreshNode_cas_fail_witnesses_intervening_cas: fresh-node contention-witness step for #7501 showing that whenever a thread readsexpected := headand later fails itsCASbecausehead ≠ expectedwithout having modifiedheaditself in between, another threadq ≠ pexecuted an intervening successfulCASonheadand entered.returning.
References #
Sequential LIFO stack specification #
Operations on a concurrent LIFO stack over element type V.
Responses returned by a concurrent LIFO stack over element type V.
Fine-grained multi-step Treiber stack machine (fresh-node model) #
Fine-grained local execution phase of a thread in the fresh-node Treiber stack (Hendler, Shavit, and Yerushalmi, §2.2, Fig. 3, p. 208).
- idle {V : Type u} : TreiberPhase V
Idle: no pending operation.
- pushAlloc {V : Type u} (val : V) : TreiberPhase V
- pushRead {V : Type u} (val : V) (node : ℕ) : TreiberPhase V
- pushCAS {V : Type u} (val : V) (node : ℕ) (expected : Option ℕ) : TreiberPhase V
- popRead {V : Type u} : TreiberPhase V
- popNext {V : Type u} (top : ℕ) : TreiberPhase V
Observed
head = some top: ready to readheap[top]. - popCAS {V : Type u} (top : ℕ) (nxt : Option ℕ) (retVal : V) : TreiberPhase V
Read
heap[top] = ⟨retVal, nxt⟩: ready to executeCAS(&head, some top, nxt), retrying frompopReadon failure. - returning {V : Type u} (resp : StackResp V) : TreiberPhase V
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.
Monotonically growing array of allocated stack nodes.
Shared
CASpointer to the current top node (nonewhen empty).- threads : P → TreiberPhase V
Per-process fine-grained execution phase.
Recorded external concurrent invocation/response history on the stack (
Obj = Unit).
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.
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.