Files
aji/docs/reference/concurrency-litmus.md
T
dev 2bbbd2135c rfc: 0015 scalar atomics and the Aji memory model accepted (revision 2) and integrated into the spec
The Aji RC11 profile (RC11 with NO-THIN-AIR; stronger than ISO C11/C++20) as
normative axioms in spec 04 §20; DRF-SC; linear atomic<T> for AtomicScalar
with atomic.new/atomic.take; ref<atomic<T>> operands; ordering tables incl.
cmpxchg failure table and two results; effects [atomic] / [atomic, atomic.weak];
target atomic_widths and E4203; E4202; enumerator as oracle (observed ⊆ allowed,
exact equality on the normative litmus corpus). Feature atomics stays reserved
until P5-2a. Q-015 resolved; record/replay and Q-017 moved to Phase 8.
RFC 0003 superseded. AIR bundle +1.9 %.
2026-10-06 00:30:35 +03:00

3.8 KiB
Raw Blame History

Concurrency Litmus Tests

Litmus tests for the memory model of spec 04 §20–§30 (RFC 0015). They are semantic tests for the oracle, the interpreter and native backends.

The tests do not define the model; spec 04 §20 does. They are its consequences, and the normative conformance corpus for the interpreter (spec 04 §20.5).

Status: draft corpus. The sets below were derived by hand from the axioms. P5-1a makes the corpus normative: every set is confirmed with the enumerator, the test files go into tests/litmus/, and the owner reviews the result. When the enumerator, the interpreter and a stated set disagree, the cause is diagnosed (spec 04 §20.5). A set is never edited to match a tool without a diagnosis.

Rules

  • Each test states its allowed outcome set and its forbidden outcome set. A test never states a single expected result.
  • Oracle: the enumerator's allowed set MUST equal the stated allowed set.
  • Interpreter:
    • under exhaustive exploration, the observed outcomes MUST equal the allowed set, for these tests;
    • for any program, under any exploration, no outcome outside the allowed set may appear.
  • Unless stated otherwise:
    • locations start at 0;
    • tasks run in parallel under one scope;
    • rlx, acq, rel, ar, sc abbreviate the five orderings.

Notation

  • ‖ separates tasks.
  • A tuple lists the reading registers in program order of the tasks, task by task.
  • final x is the value atomic.take reads after all joins.

Corpus

Test Shape Allowed Forbidden
MP rel/acq x=1 rlx; y=1 rel ‖ r0=y acq; r1=x rlx (0,0) (0,1) (1,1) (1,0)
MP rlx all rlx all four —
MP fences x=1 rlx; fence rel; y=1 rlx ‖ r0=y rlx; fence acq; r1=x rlx (0,0) (0,1) (1,1) (1,0)
SB rlx x=1; r0=y ‖ y=1; r1=x, all rlx all four —
SB rel/acq stores rel, loads acq all four, including (0,0) —
SB sc all sc (0,1) (1,0) (1,1) (0,0)
SB fences rlx accesses, fence sc between store and load on both sides (0,1) (1,0) (1,1) (0,0)
LB rlx r0=x; y=1 ‖ r1=y; x=1, all rlx (0,0) (0,1) (1,0) (1,1), a consequence of NO-THIN-AIR
IRIW acq x=1 rel ‖ y=1 rel ‖ r0=x acq; r1=y acq ‖ r2=y acq; r3=x acq includes (1,0,1,0) —
IRIW sc all sc every tuple except (1,0,1,0) (1,0,1,0)
CoRR x=1 rlx ‖ r0=x rlx; r1=x rlx (0,0) (0,1) (1,1) (1,0)
CoWW x=1 rlx; x=2 rlx, final x 2 1
relaxed counter 2 tasks × 2 add.wrap(x,1) rlx, final x 4 2, 3
CAS exclusion r0=cas.rlx.rlx(x,0→1) ‖ r1=cas.rlx.rlx(x,0→2) (old values) (0,1) (2,0) (0,0)
CAS failure acquire d=1 rlx; f=1 rel ‖ r0=cas.acq.acq(f,0→5); r1=d rlx (0,0) (0,1) (1,1) (1,0)
CAS failure relaxed as above with cas.acq.rlx (0,0) (0,1) (1,0) (1,1) —
release sequence d=1 rlx; f=1 rel ‖ add.wrap(f,2) rlx ‖ r0=f acq; r1=d rlx (0,0) (0,1) (1,1) (2,0) (2,1) (3,1) (1,0) (3,0)
channel handoff x=1 rlx; send(t) ‖ recv; r0=x rlx (1) (0)
mutex handoff lock; x=1 rlx; unlock ‖ lock; r0=x rlx; unlock, in that lock order (1) (0)
spawn/join x=1 rlx; spawn ‖ child: r0=x rlx; x=2 rlx; after join r1=x rlx (1,2) (0,·) (·,1)

Rejected programs

These are verifier tests, not outcome tests.

Test Program Code
ordinary race two tasks store the same ordinary u64 through overlapping borrows E4101
mixing ordinary load through ref<atomic<u64>> E4202
invalid ordering atomic.load.release E4201
invalid failure ordering atomic.cmpxchg.relaxed.acquire E4201
take while lent atomic.take of a cell whose ref is lent to a live task E4101