// compare_exchange binds the old value and whether it exchanged; the other operations return the old value. // expect: run // result: 28 // phase: 6 // spec: docs/spec/15-source-language.md module demo.compare_exchange fn main() -> u64 effects [atomic, atomic.weak] { let c = atomic.new(5u64); let (old, exchanged) = atomic.compare_exchange(ref c, 5u64, 9u64, acq_rel, acquire); let (old2, again) = atomic.compare_exchange(ref c, 5u64, 1u64, seq_cst, relaxed); let before = atomic.swap(ref c, 3u64, seq_cst); let x = atomic.or(ref c, 4u64, seq_cst); let y = atomic.and(ref c, 6u64, seq_cst); let z = atomic.xor(ref c, 1u64, seq_cst); let w = atomic.sub.wrap(ref c, 2u64, seq_cst); atomic.fence(acq_rel); let last = atomic.load(ref c, seq_cst); let v = atomic.take(move c); if exchanged and not again { old + old2 + before + v } else { 0 } }