Actually, the barriers matter also because evil compilers like to mess with reordering loads and stores.
If you write:
a = 5;
b = 4;
... without any barriers compiler can actually generate code that performs "b = 4" first. Even if the barriers get compiled into nothing, they can still affect the generated code load/store order.
I know you know this, but just to make sure even those people reading this later who think their software is only going to run on x86 ever need to watch out.
I think std::atomic / std::memory_order are pretty useful abstractions to get these things right.
If you write:
... without any barriers compiler can actually generate code that performs "b = 4" first. Even if the barriers get compiled into nothing, they can still affect the generated code load/store order.I know you know this, but just to make sure even those people reading this later who think their software is only going to run on x86 ever need to watch out.
I think std::atomic / std::memory_order are pretty useful abstractions to get these things right.