Allowed compiler optimizations on loops in C++11
问题 Is a C++11-compliant compiler allowed to optimize/transform this code from: bool x = true; // *not* an atomic type, but suppose bool can be read/written atomically /*...*/ { while (x); // spins until another thread changes the value of x } to anything equivalent to an infinite loop: { while (true); // infinite loop } The above conversion is certainly valid from the point of view of a single-thread program, but this is not the general case. Also, was that optimization allowed in pre-C++11? 回答1