| 1 | #include <stdatomic.h> |
| 2 | |
| 3 | _Atomic int g; |
| 4 | |
| 5 | int add_and_fetch(int x) { |
| 6 | return atomic_fetch_add_explicit(&g, x, memory_order_acq_rel) + x; |
| 7 | } |
| 8 | |
| 9 | int load_then_store(int x) { |
| 10 | int y = atomic_load_explicit(&g, memory_order_acquire); |
| 11 | atomic_store_explicit(&g, x + y, memory_order_release); |
| 12 | return y; |
| 13 | } |