spec 04 §20: Q-024 resolved (RMW events, initialization write, object orders, channel FIFO and capacity, C++20 release sequence); litmus corpus normative; P5-0 PASS; Phase 5 implementation GO

This commit is contained in:
dev committed 2026-10-06 07:26:47 +03:00
1 parent f8d2a99249
commit ce9ef03bc0
6 files changed
+89 -18

No files matched your search

+42 -7
View File
@@ -233,12 +233,26 @@ A weaker model MAY later be added only as a separate feature. Published semantic
An execution consists of events:
- atomic reads `R`, writes `W` and read-modify-writes `U` (both a read and a write), each with a location, values and an ordering;
- atomic reads `R` and writes `W`, each with a location, a value and an ordering;
- fences `F`;
- ordinary reads and writes;
- the synchronization events of the built-in primitives (§20.3).
The cell created by `atomic.new` has an initializing write, first in the modification order of its location. `atomic.take` is an ordinary read of the cell.
**Read-modify-write.** A successful read-modify-write, including a successful compare-exchange, consists of two events:
- a read event and a write event of the same location, related by `rmw`;
- the read is immediately `sb`-before the write;
- both carry the operation's ordering.
A failed compare-exchange is a single read event with the failure ordering. It writes nothing and is not in `rmw`.
**Distinguished initialization write.** Every atomic cell has one initialization write, the value given to `atomic.new`. It is a service event of the model, not a source-level access:
- it precedes every other write of the cell in `mo`;
- it happens-before every program access to the cell;
- it starts no `sw`, and is never part of a data race.
**Taking the cell.** `atomic.take` is an ordinary read of the cell. It is happens-before-ordered after every atomic access by §28.
### 20.2 Relations
@@ -247,31 +261,43 @@ An execution has:
- `sb` (sequenced-before): the program order of the events of one task;
- `rf` (reads-from): relates each read to exactly one write to the same location, whose value it reads;
- `mo` (modification order): a strict total order on the writes to each location;
- `rmw`: relates the read part of each `U` to its write part.
- `rmw`: relates the read event of each successful read-modify-write to its write event (§20.1).
Derived:
```text
fr = rf⁻¹ ; mo from-read
eco = (rf ∪ mo ∪ fr)⁺ extended coherence
rs = [W] ; (rf ; rmw)* release sequence
rs = [W] ; (rf ; rmw)* release sequence (C++20 form)
sw = [E ⊒ rel] ; ([F] ; sb)? ; rs ; rf ; [R] ; (sb ; [F])? ; [E ⊒ acq] ∪ sw_prim
hb = (sb ∪ sw)⁺ happens-before
```
`E ⊒ rel` is a write, RMW or fence whose ordering is `release`, `acq_rel` or `seq_cst`. `E ⊒ acq` is a read, RMW or fence whose ordering is `acquire`, `acq_rel` or `seq_cst`. `[X]` restricts a relation to events in `X`.
`E ⊒ rel` is a write or fence whose ordering is `release`, `acq_rel` or `seq_cst`. `E ⊒ acq` is a read or fence whose ordering is `acquire`, `acq_rel` or `seq_cst`. A read-modify-write's two events carry its ordering, so its write event is `⊒ rel` and its read event `⊒ acq` as the ordering says. `[X]` restricts a relation to events in `X`.
The release sequence is deliberately the C++20 form. It continues only through read-modify-writes that read from it, not through later plain stores of the releasing task (as C11 and the original RC11 do).
### 20.3 Synchronization of built-in primitives
Each task, channel and mutex has a total order of its operations, consistent with `hb`. It is not part of the `seq_cst` order: these are lock semantics, as for C++ mutexes. `sw_prim` contains:
**Object orders.** Each task, channel and mutex has a total order of its operations. These orders are not part of the `seq_cst` order: they are lock semantics, as for C++ mutexes. Each order is **consistent with `hb`**: for any `a` and `b` in the domain of the order, if `a hb→ b` then `a` precedes `b` in the order. No `hb` edge points backwards in it.
**`sw_prim`** contains:
- `task.spawn` → the first event of the spawned task;
- the last event of a task → the `task.join` (or `task.join.cancel`) that returns its result;
- a successful `channel.send` → the `channel.recv` (or `select` arm) that receives that message;
- a successful `channel.send` of a value → the `channel.recv` (or `select` arm) that obtains that exact value;
- `channel.close_sender` of the last sender → the `closed` outcome it causes;
- `mutex.unlock` → the next `mutex.lock` of the same mutex;
- `task.cancel` → the `cancelled` outcome it causes.
**Channels.**
- A buffered channel is FIFO. Successful sends enter one enqueue order of the channel, and receives remove values in that order. With several senders, the execution (the scheduler) determines the enqueue order. Once it exists, receivers observe it.
- A rendezvous channel (capacity 0) has no buffer. The scheduler chooses which waiting send is matched with a receive.
- Each value is received at most once.
- **Capacity affects blocking and scheduling, not memory ordering, in Aji 0.1.** A receive that frees a slot, and the send it unblocks, are related by nothing beyond the edges listed above.
- A semantics in which capacity itself creates synchronization (as in Go) may only be introduced as a separate feature by an RFC. The published model is never strengthened silently.
### 20.4 Consistency
An execution is consistent iff:
@@ -298,6 +324,15 @@ The **outcomes** of a program are the observable behaviors of its consistent exe
There are two distinct obligations:
- **Axiomatic oracle.** `tools/litmus` holds an enumerator derived from §20.1–§20.4. For a small program it enumerates exactly the consistent executions, and hence the allowed outcomes. It is an executable oracle, not the definition. When it, the interpreter and a stated outcome set disagree, the disagreement is diagnosed as a defect of a tool or of the stated set. The model changes only through an RFC.
**Status of the corpus.** The 20 tests of `tests/litmus/` are the normative conformance corpus of the Aji 0.1 atomic model. They are normative consequences of §20.1–§20.4, not its definition. For each test:
```text
oracle allowed set == stated allowed set
interpreter exhaustive outcomes == stated allowed set
```
Changing the allowed or forbidden set of a published test changes the memory model and requires an RFC. New tests that only cover the existing axioms may be added as extensions of the corpus.
- **Interpreter exploration.**
- For every program, every outcome the interpreter produces is allowed (`observed ⊆ allowed`).
- For each test of the finite normative litmus corpus (`reference/concurrency-litmus.md`), exhaustive exploration produces every allowed outcome (`observed_exhaustive = allowed`).