Final whole-stream adversarial review came back CLEAN (no CRITICAL/MEDIUM/LOW). Close the one informational gap it noted: extend examples/1703 with a #run comptime swap so swap's comptime VM arm is locked (742, matches runtime) — every op now has comptime↔runtime corpus coverage. Docs: PLAN-ATOMICS.md status banner (COMPLETE); PLAN-POST-METATYPE.md Stream A marked done (unblocks B2-channels + C-parallel); readme.md gains a user-facing Atomics section. Suite green (721/0).
17 lines
699 B
Plaintext
17 lines
699 B
Plaintext
// Atomic($T).swap — atomic exchange (LLVM atomicrmw xchg): store the new value,
|
|
// return the OLD one. Stream A (atomics) A.3. Single-thread.
|
|
// Covers swap at BOTH comptime (#run) and runtime — they must agree.
|
|
#import "modules/std.sx";
|
|
#import "modules/std/atomic.sx";
|
|
|
|
c_swap :: () -> i64 { a := Atomic(i64).init(7); old := a.swap(42, .seq_cst); return old * 100 + a.load(.seq_cst); }
|
|
G_SWAP :: #run c_swap(); // 742 (old 7, now 42)
|
|
|
|
main :: () {
|
|
a := Atomic(i64).init(7);
|
|
old := a.swap(42, .acq_rel);
|
|
print("swap old: {}\n", old); // 7
|
|
print("swap now: {}\n", a.load(.acquire)); // 42
|
|
print("comptime swap: {}\n", G_SWAP); // 742 (matches runtime)
|
|
}
|