Does the C++11 memory model allow hoisting relaxed atomic loads out of loops?
Consider the following code: #include <atomic> extern std::atomic<int> i; void f(void) { while (!i.load(std::memory_order_relaxed)) ; } I'm looking for a citation from the C++11 standard that says that the compiler is not allowed to transform the loop into if (!i.load(std::memory_order_relaxed)) { while (1) ; } I've seen some discussion here but nothing conclusive. Edit : A previous version of this post called an extern function inside the loop. Edit 2 : For motivation: The book "Effective Java" says that the HotSpot VM performs the following transformation: while (!done) i++; to if (!done)