Phase 5: atomics through every layer (RFC 0015)
AIR: linear atomic<T> (AtomicScalar), atomic.new/take/load/store/RMW/ cmpxchg (two results)/fence with explicit orderings; feature atomics published. Verifier: ordering tables (E4201), ordinary access (E4202), effects [atomic] / [atomic, atomic.weak], linearity, take while lent (E4101, also for mutex.take). Interpreter: timestamped message machine (src/interp/weak.zig); views travel through spawn/join, channels, mutexes, close and cancel; seq_cst reads the latest message and programs without weak reads make no extra draw (existing records unchanged). aji explore: exhaustive exploration that branches only before visible operations. Litmus: 20/20 tests give exactly the oracle's sets; differential test (1500 random programs) found no unsound outcome. .aji layer 10, Quick Reference atomics, source coverage 67/67, audit report atomic_operations. AIR bundle +5.9 %, QUICK.md +0.5k.
This commit is contained in:
1 parent
ce9ef03bc0
commit
4242132b2a
70 files changed
+2630
-80
No files matched your search
@@ -0,0 +1,22 @@
|
||||
// Quick Reference: atomics.
|
||||
// expect: run
|
||||
// result: 6
|
||||
// phase: 6
|
||||
// spec: docs/agent/quick-reference.md
|
||||
module demo.qratomics
|
||||
|
||||
fn main() -> u64
|
||||
effects [atomic, atomic.weak]
|
||||
{
|
||||
let count = atomic.new(0u64); // atomic<T>: bool or an integer up to 64 bits; linear
|
||||
{
|
||||
ref c = count; // every operation takes `ref`; lend `c` to tasks
|
||||
let old = atomic.add.wrap(c, 1u64, relaxed); // swap, add.wrap, sub.wrap, and, or, xor return the old value
|
||||
atomic.store(c, 5u64, release);
|
||||
let v = atomic.load(c, acquire);
|
||||
let (prev, exchanged) = atomic.compare_exchange(c, 5u64, 6u64, acq_rel, acquire);
|
||||
atomic.fence(seq_cst);
|
||||
}
|
||||
let total = atomic.take(move count); // needs no live borrow of count
|
||||
total
|
||||
}
|
||||
Reference in new issue
Block a user