logoalt Hacker News

ack_completetoday at 1:57 AM1 replyview on HN

Yes, but the compiler does have to preserve any observable behavior produced by the call to the standard library function. Being able to omit this inserted yield() by the as if rule would mean that it isn't observable, which would also mean that the compiler could already add or not add it anywhere as needed without changing the behavior of the program. Which would seemingly make the inserted yield() pointless as it would have no effect.


Replies

leni536today at 12:49 PM

Arguably the only change to program behavior is to performance characteristics on hosted environments. It does not change any observable behavior otherwise.

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).