October 2018
Beginner
794 pages
19h 23m
English
Often, one would like to wait forever, or until a signal arrives. One way to do so is the very simple, but very bad, terribly expensive spin on the CPU code such as this:
while (1);
Ugh! That's just ugly: please do not write code like that!
Slightly better, but still quite off, is this:
while (1) sleep(1);
The pause can be used to effectively and efficiently set up a useful wait forever or until I receive any signal semantic, as follows:
while (1) (void)pause();
This semantic is very useful for this wait forever or until I receive any signal situation, as it's inexpensive (hardly any CPU usage as the pause(2) has the caller immediately go to sleep), and get unblocked only when a signal arrives. ...
Read now
Unlock full access