; Two tasks add to one cell with relaxed add.wrap: atomicity makes the total exact on every schedule. ; expect: run ; schedules: 30 ; quantum: 1 ; result: 6 ; phase: 5 ; spec: docs/spec/04-concurrency-and-atomics.md module test.atomic_counter air 0 lang 0.1 features [atomics, cancellation, effects, ownership, tasks] fn @bump(%c: ref>) -> u64 effects [atomic, atomic.weak] entry: %one = const.u64 1 %a = atomic.add.wrap.relaxed %c, %one %b = atomic.add.wrap.relaxed %c, %one %d = atomic.add.wrap.relaxed %c, %one ret %d fn @main() -> u64 effects [atomic, atomic.weak, task.spawn, task.wait] entry: %z = const.u64 0 %cell = atomic.new %z %r = borrow.ref %cell %s = task.scope.begin %t1 = task.spawn %s, @bump(%r) %t2 = task.spawn %s, @bump(%r) %x1 = task.join %t1 %x2 = task.join %t2 task.scope.end %s borrow.end %r %total = atomic.take %cell ret %total