Question Details

No question body available.

Tags

c++ language-lawyer atomic

Answers (1)

Accepted Answer Available
Accepted Answer
June 16, 2026 Score: 9 Rep: 381,457 Quality: Expert Completeness: 100%

Generally yes, a compiler can statically decide that a certain order of atomic operations is the only one that can ever happen in the executable it builds, according to the current standard. (I don't think it's plausible that a mainstream real-world compiler would do that in a loop with a 1-second sleep. That's a very long time for normal computers, so it's unlikely that this possible execution would be the one that actually happens if compiled as written.)

For now the committee's guidelines are for compilers not to do optimizations like this until they figure out a way to let code opt-in to it, rather than having to use volatile atomic everywhere to opt out.