Store buffer
Hardware is sneaky
A store buffer is a hardware queue sitting between a CPU core and its L1 cache.
When a core executes a store instruction, the value is written to the store buffer first, not directly to cache.
The core continues executing the next instructions immediately (without waiting for the store to reach cache/memory).
Thread 1:
data = 42;
ready.store(true, std::memory_order_release); // drains store buffer
Thread 2:
if (ready.load(std::memory_order_acquire))
use(data); // guaranteed to see 42
C++ memory_order_release drains the CPU’s store buffer so other cores can actually see your write. Without it, your data might be “written” but still invisible.
Write a comment