I know that generally a modern C++ compiler and processor will perform certain optimizations by sometimes reordering instructions for better performance.
C++11 introduces a sequenced before relation. And if instruction A
comes before instruction B
in program order, we say that A
is sequenced before B
.
int data = 0;
bool ready = 0;
// A is sequenced before B
data = 6; // A
ready = true; // B
C++11 also defines a requirement for sequenced before relation.
Given any two evaluations A and B, if A is sequenced before B, then the execution of A shall precede the execution of B.
This puzzles me. To me, it conflicts with out-of-order executions because the reordering may break the above required property. E.g., when store to ready
happens before store to data
.
Does the definition above stop instruction reordering? (I'm pretty sure it's not. But what did I miss?)