C++26: Trivial infinite loops are no longer undefined behaviour
Thread
Unofficial Hacker News client; not affiliated with Y Combinator.
C++26: Trivial infinite loops are no longer undefined behaviour
Unofficial Hacker News client; not affiliated with Y Combinator.
JoshTriplett · · focus · HN ↗
Insert screaming here.
An infinite loop, with no library calls whatsoever, gets a system call inserted. That's a horrible surprise waiting to happen.
The entire concept of the "forward progress guarantee" is broken. An infinite loop should compile to an infinite loop. Nothing more, nothing less.
marcosdumay · · focus · HN ↗
I think you are misinterpreting that. That phrase unambiguously says the loop is preserved on the final binary.
JoshTriplett · · focus · HN ↗
leni536 · · focus · HN ↗
ack_complete · · focus · HN ↗
leni536 · · focus · HN ↗
In environments where there are strong forward progress guarantees a busy infinite loop does the same as far as the abstract machine is concerned, as the OS will eventually put the thread to sleep anyway and other threads can make progress. How soon the thread yields is not "observable behavior" (as defined by the standard document).