stdatomic
Why don’t compilers merge redundant std::atomic writes?
The C++11 / C++14 standards as written do allow the three stores to be folded/coalesced into one store of the final value. Even in a case like this: y.store(1, order); y.store(2, order); y.store(3, order); // inlining + constant-folding could produce this in real code The standard does not guarantee that an observer spinning on y … Read more
Will two atomic writes to different locations in different threads always be seen in the same order by other threads?
This kind of reordering test is called IRIW (Independent Readers, Independent Writers), where we’re checking if two readers can see the same pair of stores appear in different orders. Related, maybe a duplicate: Acquire/release semantics with 4 threads The very weak C++11 memory model does not require that all threads agree on a global order … Read more