Suspend a thread until a timeout or signal occurs
#include <time.h> int nanosleep( const struct timespec* rqtp, struct timespec* rmtp );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The nanosleep() function causes the calling thread to be suspended from execution until either:
Or:
At the end of the suspension, the thread becomes READY and is scheduled to run as normal, based on priority and the scheduling algorithm.
The nanosleep() function uses CLOCK_REALTIME; clock_nanosleep() is similar, but you can choose which clock to use, and you can specify a relative or absolute time.
This function can interfere with the kernel's efforts to manage power usage. The suspension time may be longer than requested because the argument value is rounded up to be a multiple of the system timer resolution (see the Understanding the Microkernel's Concept of Time chapter of the QNX Neutrino Programmer's Guide) or because of scheduling and other system activity.
Safety: | |
---|---|
Cancellation point | Yes |
Interrupt handler | No |
Signal handler | No |
Thread | Yes |