nanosleep()

suspend calling thread for given interval (in nanoseconds) 

Function


SYNOPSIS

#include <time.h>

int nanosleep(const struct timespec *req, struct timespec *rem);


DESCRIPTION

The nanosleep() function suspends the calling thread until either the time interval specified by req has elapsed or a signal is delivered to the calling thread. The suspension time may be longer than requested because the argument value is rounded up to an integer multiple of the sleep resolution, or due to the scheduling of other activity by the system.


PARAMETERS

req 

Is the number of real-time (as opposed to CPU-time) seconds and nanoseconds to suspend the calling thread.

rem 

Points to a structure to receive the remaining time if nanosleep() is interrupted by a signal. This pointer may be NULL.


RETURN VALUES

If successful, nanosleep() returns 0. If interrupted by a signal, the remaining sleep time is returned in rem if it is non-NULL. On failure, or if interrupted by a signal, it returns a value of -1 and sets errno to one of the following values:

EINTR 

A signal interrupted the call.

EINVAL 

req specifies a nanosecond value greater than or equal to 1,000 million.


CONFORMANCE

UNIX 98.


MULTITHREAD SAFETY LEVEL

MT-Safe.


PORTING ISSUES

nanosleep() is implemented using an interruptible wait function, and does not use signals. Hence there are no interactions with SIGALRM handling, or with any other wait function (for example, sleep()), as there are on some UNIX platforms.

On 8.1/2012R2/10/2016/2019/11/2022, waitable timers with 100-nanosecond resolution are available, so nanosleep() has 100-nanosecond accuracy.

nanosleep() can be configured to wake the system from a suspended power conservation mode when the specified interval expires. See _NutConf() for more details.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
_NutConf(), alarm(), getitimer(), kill(), nap(), pause(), sigaction(), signal(), sigpause(), sleep(), usleep()


PTC MKS Toolkit 10.4 Documentation Build 39.