Files
aji/docs/reference/concurrency-litmus.md
T
dev 17a55a7fef Initial import: Aji 0.1 draft spec and Zig scaffolding
Draft specification, RFCs, reference registries and examples, plus the
reference-implementation skeleton: build.zig, diagnostic envelope with
error-code registry synced to docs, aji CLI, conformance runner with seed
tests, CI and contributor docs.
2026-10-04 11:59:13 +03:00

60 lines
1.4 KiB
Markdown

# Concurrency Litmus Tests
These are semantic tests for the interpreter, verifier and native backend. Syntax is illustrative.
## MP — message publication
Writer:
```aji
atomic.store(ref value, 42, relaxed);
atomic.store(ref ready, true, release);
```
Reader:
```aji
if atomic.load(ref ready, acquire) {
let v = atomic.load(ref value, relaxed);
assert v == 42;
}
```
If the reader observes the release publication, observing the prior value store must be consistent with the happens-before relation.
## SB — store buffering
Initially `x = 0`, `y = 0`, both atomic.
Task A:
```text
store x=1 relaxed
r1 = load y relaxed
```
Task B:
```text
store y=1 relaxed
r2 = load x relaxed
```
Outcome `r1=0, r2=0` is permitted under relaxed ordering. The interpreter's weak-memory test mode must not incorrectly forbid it.
## Mutex handoff
Writes performed while holding a mutex before unlock must be visible to a later holder after successful lock acquisition.
## Channel handoff
Writes sequenced before successful `channel.send` are visible after the matching receive. Ownership of the moved message belongs only to the receiver after transfer.
## Spawn/join
Parent operations sequenced before spawn happen-before child start. Child operations happen-before successful join return.
## Invalid ordinary race
Two tasks writing the same ordinary `u64` through overlapping unsynchronized aliases must be rejected before execution.