I heard that some unix implementations use alarm(2)
to implement sleep
function.
If it is true, I guess following code might not safe because SIGALRM
may be sent to process, which is received by root thread.
#include <pthread.h>
#include <unistd.h>
void *doit(void *arg) {
sleep(1);
return NULL;
}
int main(int argc, char *argv[]) {
pthread_t th;
pthread_create(&th, NULL, doit, NULL);
sleep(5);
pthread_join(th, NULL);
return 0;
}
Is it safe to call sleep(3)
, usleep(3)
or nanosleep(2)
in thread?