Is function sleep() in C an active wait or passive wait?
Since it stops the thread running, is it always checking if the time has passed like:
while(1){
//need to wake?
}
Or a passive like:
alarm(sec);
pause(); // wait for the alarm and sleeping?
The system is unix.
Bathsheba :
sleep is not a standard C library function.\n\nIf your platform has it, it almost certainly will make a call to the operating system to suspend the thread (that is, in your notation, passive).\n\nIt will not adopt a while(1){}-type idiom as that will unnecessarily burn the CPU.",
2016-06-01T10:05:18
Mohan :
There are two general approaches to the implementation of the sleep() function.\n\nOne is to use the alarm() function to schedule a SIGALRM signal and then suspend the calling thread waiting for that signal. The other is to implement an independent facility. \n\nFunction sleep() is in passive wait in unix.",
2016-06-01T10:11:01