1 NANOSLEEP(3C)            Standard C Library Functions            NANOSLEEP(3C)
   2 
   3 
   4 
   5 NAME
   6        nanosleep, thrd_sleep - high resolution sleep
   7 
   8 SYNOPSIS
   9        #include <time.h>
  10 
  11        int nanosleep(const struct timespec *rqtp,
  12             struct timespec *rmtp);
  13 
  14        #include <threads.h>
  15 
  16        int thrd_sleep(const struct timespec *rqtp,
  17             struct timespec *rmtp);
  18 
  19 
  20 DESCRIPTION
  21        The nanosleep() and thrd_sleep() functions cause the current thread to
  22        be suspended from execution until either the time interval specified by
  23        the rqtp argument has elapsed or a signal is delivered to the calling
  24        thread and its action is to invoke a signal-catching function or to
  25        terminate the process. The suspension time may be longer than requested
  26        because the argument value is rounded up to an integer multiple of the
  27        sleep resolution or because of the scheduling of other activity by the
  28        system. But, except for the case of being interrupted by a signal, the
  29        suspension time will not be less than the time specified by rqtp, as
  30        measured by the system clock, CLOCK_REALTIME.
  31 
  32 
  33        The use of the nanosleep() and thrd_sleep() functions has no effect on
  34        the action or blockage of any signal.
  35 
  36 RETURN VALUES
  37        If the nanosleep() or thrd_sleep() function returns because the
  38        requested time has elapsed, its return value is 0.
  39 
  40 
  41        If the nanosleep() function returns because it has been interrupted by
  42        a signal, the function returns a value of -1 and sets errno to indicate
  43        the interruption. If the rmtp argument is non-NULL, the timespec
  44        structure referenced by it is updated to contain the amount of time
  45        remaining in the interval (the requested time minus the time actually
  46        slept). If the rmtp argument is NULL, the remaining time is not
  47        returned.
  48 
  49 
  50        If nanosleep() fails, it returns -1 and sets errno to indicate the
  51        error.
  52 
  53 
  54        The thrd_sleep() function may fail for identical reasons as the
  55        nanosleep() function and returns -1; however, the C11 standard does not
  56        define that errno should be set, therefore callers of thrd_sleep()
  57        cannot rely on errno being set or staying the same across a call to
  58        thrd_sleep() .
  59 
  60 
  61 ERRORS
  62        The nanosleep() function will fail if:
  63 
  64        EINTR
  65                  The nanosleep() function was interrupted by a signal.
  66 
  67 
  68        EINVAL
  69                  The rqtp argument specified a nanosecond value less than zero
  70                  or greater than or equal to 1000 million.
  71 
  72 
  73        ENOSYS
  74                  The nanosleep() function is not supported by this
  75                  implementation.
  76 
  77 
  78 ATTRIBUTES
  79        See attributes(5) for descriptions of the following attributes:
  80 
  81 
  82 
  83 
  84        +--------------------+-------------------+
  85        |  ATTRIBUTE TYPE    |  ATTRIBUTE VALUE  |
  86        +--------------------+-------------------+
  87        |Interface Stability | Committed         |
  88        +--------------------+-------------------+
  89        |MT-Level            | MT-Safe           |
  90        +--------------------+-------------------+
  91        |Standard            | See standards(5). |
  92        +--------------------+-------------------+
  93 
  94 SEE ALSO
  95        sleep(3C), time.h(3HEAD), attributes(5), standards(5)
  96 
  97 
  98 
  99                                 March 27, 2016                   NANOSLEEP(3C)