; A strong compare-exchange returns the old value and whether it exchanged; a non-seq_cst one needs atomic.weak. ; expect: run ; result: 14 ; phase: 5 ; spec: docs/spec/04-concurrency-and-atomics.md module test.atomic_cmpxchg air 0 lang 0.1 features [atomics, effects, ownership] fn @main() -> u64 effects [atomic, atomic.weak] entry: %five = const.u64 5 %c = atomic.new %five %r = borrow.ref %c %seven = const.u64 7 %old1, %ok1 = atomic.cmpxchg.seq_cst.seq_cst %r, %five, %seven assert %ok1 %old2, %ok2 = atomic.cmpxchg.acq_rel.acquire %r, %five, %five %no = const.bool true %failed = xor.bool %ok2, %no assert %failed borrow.end %r %v = atomic.take %c %sum = add.checked.u64 %v, %old2 ret %sum