Shared memory
Nothing runs in the order you wrote it
Why the compiler and the processor move your statements around, and what that means for code that publishes something.
10 minutes · reordering · as-if rule · publication
The as-if rule, and who it applies to
A compiler may transform your program however it likes as long as a *single-threaded* observer cannot tell. Reordering two independent statements is invisible to that observer, so it is allowed, and it is done constantly — it is most of what an optimiser is.
The word doing the work is single-threaded. Another thread is not that observer, and it can absolutely tell. The two stores in the broken double-checked-locking exercise were independent as far as one thread is concerned; another thread reading the field is the only thing that can distinguish their order, and the language deliberately does not consider it.