thrd_sleep Subroutine

Purpose

This subroutine causes the thread to sleep or pause until a time interval duration elapses.

Library

Standard C Library (libc.a)

Syntax

#include <threads.h>
int thrd_sleep(const struct timespec *duration, struct timespec *remaining);

Description

The thrd_sleep subroutine suspends running of the calling thread until either the interval specified by the duration parameter elapses or a signal which is not being ignored, is received. If interrupted by a signal and the remaining argument is not null, the amount of remaining time (the requested interval minus the time actually slept) is stored in the interval it points to. The duration and remaining arguments potentially point to the same object. The suspension time is longer than requested because the interval is rounded up to an integer multiple of the sleep resolution or because of the scheduling of other activities by the system. However, when the thread is interrupted by a signal, the suspension time is not less than the specified time, as measured by the TIME_UTC system clock .

Parameters

Item Description
duration Specifies the number of time intervals for which (or until a signal is received) a calling thread is suspended.
remaining Specifies the amount of remaining time (the requested interval minus the time actually slept).

Return Values

The thrd_sleep subroutine returns zero if the requested time elapses. The thrd_sleep subroutine returns -1 if it is interrupted by a signal. The thrd_sleep subroutine returns a negative value if it fails to complete.

Files

Item Description
threads.h Standard macros, data types, and subroutines are defined by the threads.h file.