// 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: 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 }