You most definitely cannot trust your intuition.
What can you trust?
It turns out that there are a few reasonably simple rules that
allow you to make good use of memory barriers.
This section derives those rules, for those who wish to get
to the bottom of the memory-barrier story, at least from the viewpoint
of portable code.
If you just want to be told what the rules are rather than suffering
through the actual derivation,
please feel free to skip to Section .
The exact semantics of memory barriers vary wildly from one CPU to another, so portable code must rely only on the least-common-denominator semantics of memory barriers.
Fortunately, all CPUs impose the following rules:
Therefore, if you need to use memory barriers in portable code, you can rely on all of these properties.14.1Each of these properties is described in the following sections.