- Coherence: single memory location agreement; consistency: ordering across locations.
- Relaxed models (TSO, ARM/POWER) require fences for cross-core visibility.
- Atomics provide ordering (acquire/release, seq_cst) and coherence interaction.
#include
std::atomic x{0}, y{0};
// Thread A
x.store(1, std::memory_order_release);
std::atomic_thread_fence(std::memory_order_seq_cst);
y.store(1, std::memory_order_relaxed);
// Thread B
if (y.load(std::memory_order_acquire)) {
int r = x.load(std::memory_order_acquire);
}