Updated: April 19, 2023 |
Make a thread sleep
#include <threads.h> #include <time.h> int thrd_sleep( const struct timespec *duration, struct timespec *remaining );
For the relative thrd_sleep() function, if remaining isn't NULL, the timespec structure referenced by it is updated to contain the amount of time remaining in the interval (the requested time minus the time actually slept). If it's NULL, the remaining time isn't returned.
The absolute thrd_sleep() function has no effect on the structure referenced by remaining.
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The thrd_sleep() function suspends the current thread from execution until either the time interval specified by the duration argument has elapsed, or a signal is delivered to the calling thread, and the signal's action is to invoke a signal-catching function or terminate the process. This function always uses CLOCK_REALTIME.
The suspension time may be longer than requested because the argument value is rounded up to a multiple of the sleep 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. Except for the case of being interrupted by a signal, the suspension time isn't less than the time interval specified by duration, as measured by the CLOCK_REALTIME clock.
Using the thrd_sleep() function has no effect on the action or blockage of any signal.
Zero if the requested time has elapsed, or -1 if thrd_sleep() has been interrupted by a signal or failed.
Safety: | |
---|---|
Cancellation point | Yes |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |