![]() |
![]() |
![]() |
![]() |
Suspend a thread for a given time
#include <unistd.h> int usleep( useconds_t useconds );
libc
The usleep() function suspends the calling thread until useconds microseconds of realtime have elapsed, or until a signal that isn't ignored is received. The time spent suspended could be longer than the requested amount due to the scheduling of other, higher-priority threads.
The useconds argument must be less than 1,000,000. If useconds is 0, usleep() has no effect.
/* * The following program sleeps for the * number of microseconds specified in argv[1]. */ #include <stdlib.h> #include <unistd.h> int main( int argc, char **argv ) { useconds_t microseconds; microseconds = (useconds_t)strtol( argv[1], NULL, 0 ); if( usleep( microseconds ) == 0 ) { return EXIT_SUCCESS; } return EXIT_FAILURE; }
Safety: | |
---|---|
Cancellation point | Yes |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |
alarm(), nanosleep(), sigaction(), sleep(), timer_create(), timer_delete(), timer_getoverrun(), timer_gettime(), timer_settime(), ualarm()
![]() |
![]() |
![]() |
![]() |