Memory Fence
From https://en.cppreference.com/w/cpp/atomic/atomic_thread_fence :
atomic_thread_fence imposes stronger synchronization constraints than an atomic store operation with the same std::memory_order. While an atomic store-release operation prevents all preceding reads and writes from moving past the store-release, an atomic_thread_fence with memory_order_release ordering prevents all preceding reads and writes from moving past all subsequent stores.
Just a small herd7 example to help me unpack the text.
1 | C fence_vs_atomic |
The specified result can occur with approach 1 but not with approach 2, because a fence offers stronger synchronization than an atomic store.