; Release/acquire publication: whenever the reader sees the flag, it sees the data (never 1 with 0). ; expect: run ; schedules: 30 ; quantum: 1 ; result: 1 ; phase: 5 ; spec: docs/spec/04-concurrency-and-atomics.md module test.atomic_publication air 0 lang 0.1 features [atomics, cancellation, effects, ownership, tasks] fn @writer(%d: ref>, %f: ref>) -> u64 effects [atomic, atomic.weak] entry: %v = const.u64 42 atomic.store.relaxed %d, %v %t = const.bool true atomic.store.release %f, %t ret %v fn @main() -> u64 effects [atomic, atomic.weak, task.spawn, task.wait] entry: %z = const.u64 0 %no = const.bool false %data = atomic.new %z %flag = atomic.new %no %rd = borrow.ref %data %rf = borrow.ref %flag %s = task.scope.begin %t = task.spawn %s, @writer(%rd, %rf) %seen = atomic.load.acquire %rf %val = atomic.load.relaxed %rd %w = task.join %t task.scope.end %s borrow.end %rd borrow.end %rf %dv = atomic.take %data %fv = atomic.take %flag cbr %seen, @published(), @done() published: %ok = eq.u64 %val, %w assert %ok br @done() done: %one = const.u64 1 ret %one