To expand on what to3m said. The code was transformed into something like this:
int launched = 0;
start_thread(...);
if (!launched) {
while (true) {}
}
That's a perfectly legal optimization. The integer here isn't atomic and if another thread modifies the variable, that would be a data race and those have undefined behavior. Therefore, the compiler can assume that there is no race and move the comparison out of the loop.Changing it to be "std::atomic<int> launched;" fixes that problem.