Home:ALL Converter>Is function sleep() active on passive?

Is function sleep() active on passive?

Ask Time:2016-06-01T17:59:53         Author:Hugo

Json Formatter

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.

Author:Hugo,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/37565439/is-function-sleep-active-on-passive
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
yy