4 ms·
Compilers choose to not remove it in this case, probably because there is no clean way of making assumptions that provide a way out, unlike in the example from
by detaro 5y ago
Compilers choose to not remove it in this case, probably because there is no clean way of making assumptions that provide a way out, unlike in the example from the link, but the core point is as I mentioned "making progress", specificall< the Progress guarantee (https://en.cppreference.com/w/cpp/language/memory_model#Progress_guarantee https://en.cppreference.com/w/cpp/language/memory_model#Prog...)
In a valid C++ program, every thread eventually does one of the following:
* terminate
* makes a call to an I/O library function
* performs an access through a volatile glvalue
* performs an atomic operation or a synchronization operation
It's fairly obvious how a loop that has none of these side-effects is thus a target to get turned into one that's guaranteed to terminate.