4 ms·
In particular, the “multi-threaded using volatile” example is technically incorrect because the compiler is allowed to move non-volatile accesses across volatil
by comex 6y ago
In particular, the “multi-threaded using volatile” example is technically incorrect because the compiler is allowed to move non-volatile accesses across volatile ones. [1] To make it correct (but still only on x86), you’d have to use std::sync::atomic::compiler_barrier.
[1] https://gcc.gnu.org/onlinedocs/gcc/Volatiles.html https://gcc.gnu.org/onlinedocs/gcc/Volatiles.html