thrd_sleep()

Make a thread sleep

Synopsis:

#include <threads.h>
#include <time.h>

int thrd_sleep( const struct timespec *duration,
                struct timespec *remaining );

Arguments:

duration
A pointer to a timespec structure that specifies the requested time to sleep, relative to the current time.
remaining
NULL, or a pointer to a timespec in which the function can store the amount of time remaining in an interval.

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.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

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.

Returns:

Zero if the requested time has elapsed, or -1 if thrd_sleep() has been interrupted by a signal or failed.

Classification:

C11

Safety:  
Cancellation point Yes
Interrupt handler No
Signal handler Yes
Thread Yes