3 ms·
Compilers have been assuming single-threaded memory access by default since, forever? If you want your code to work with multiple threads, then you have to expl
by sreque 7y ago
Compilers have been assuming single-threaded memory access by default since, forever? If you want your code to work with multiple threads, then you have to explicitly write code to do so. Otherwise, the compiler is liable to store things in registers, shuffle instructions around, and do whatever it feels like to optimize performance for the single-threaded case. If the compiler didn't do this, then every program would run many many times slower than it does.
Doing some quick googling, this article seems to explain things well from the perspective of a C# developer: https://afana.me/archive/2015/07/10/memory-barriers-in-dot-net.aspx/ https://afana.me/archive/2015/07/10/memory-barriers-in-dot-n...