2 ms·
The difference is that reordering is not observable with just one thread. Both language optimizations and CPU OOO don't change semantics within a single thread.
by pornel 7y ago
The difference is that reordering is not observable with just one thread. Both language optimizations and CPU OOO don't change semantics within a single thread. If you use higher-level primitives like mutexes, they come with fences that also preserve that illusion.
It does become observable when you try to do synchronization yourself with atomics, without setting appropriate ordering requirements. Lock-free algorithms are usually tricky, and implementing them with minimum ordering requirements makes them even more puzzling.