There is no guarantee by the standard that without synchronization or ordering guarantees given by e.g. std::atomic
the other thread will ever see the write to run
.
As a matter of fact the compiler would be perfectly fine to only check once that write
is true and since the thread itself never writes to it cache the value without ever reloading it. Now practically speaking with all the c library calls going on the compiler generally cannot know that none of functions writes to run
and under x86 you don't have to worry about not seeing updates from other processors to memory, so it will in practice work (and even under other architectures a context switch would probably resolve the problem).
But if you're talking purely from the standard's point of view? No guarantees whatsoever.