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.
38 lines
911 B
Rust
38 lines
911 B
Rust
// With seq_cst only, a function declares atomic and not atomic.weak: interleaving reasoning is exact.
|
|
// expect: run
|
|
// schedules: 30
|
|
// quantum: 1
|
|
// result: 1
|
|
// phase: 6
|
|
// spec: docs/spec/15-source-language.md
|
|
module demo.sc_only
|
|
|
|
fn flip(x: ref<atomic<u64>>, y: ref<atomic<u64>>) -> u64
|
|
effects [atomic]
|
|
{
|
|
atomic.store(x, 1u64, seq_cst);
|
|
atomic.load(y, seq_cst)
|
|
}
|
|
|
|
fn main() -> u64
|
|
effects [atomic, task.spawn, task.wait]
|
|
{
|
|
let x = atomic.new(0u64);
|
|
let y = atomic.new(0u64);
|
|
var both: u64 = 0;
|
|
{
|
|
ref rx = x;
|
|
ref ry = y;
|
|
scope s {
|
|
let a = task.spawn(s, flip, rx, ry);
|
|
let b = task.spawn(s, flip, ry, rx);
|
|
let r0 = task.join(move a);
|
|
let r1 = task.join(move b);
|
|
both = r0 + r1;
|
|
}
|
|
}
|
|
let vx = atomic.take(move x);
|
|
let vy = atomic.take(move y);
|
|
if both == 0 { 0 } else { 1 }
|
|
}
|