nanosleep()

Приостановить поток до истечения времени или прихода сигнала

Прототип:

#include <time.h>
int nanosleep( const struct timespec *rqtp,
struct timespec *rmtp );

Аргументы:

rqtp
A pointer to a struct timespec that specifies the time interval for which you want to suspend the thread.
rmtp
NULL, or a pointer to a struct timespec where the function can store the amount of time remaining in the interval (the requested time minus the time actually slept).

Библиотека:

libc

Описание:

The nanosleep() function causes the calling thread to be suspended from execution until either:


Note: The suspension time may be longer than requested because the argument value is rounded up to be a multiple of the system timer resolution or because of scheduling and other system activity.

Возвращаемое значение:

0
The requested time has elapsed.
-1
Функция была прервана сигналом. Код ошибки записан в errno.

Коды ошибок:

EAGAIN
All timers are in use. You'll have to wait for a process to release one.
EFAULT
A fault occurred trying to access the buffers provided.
EINTR
The nanosleep() function was interrupted by a signal.
EINVAL
The number of nanoseconds specified by the tv_nsec member of the struct timespec pointed to by rqtp is less than zero or greater than or equal to 1000 million.

Классификация:

POSIX 1003.1 TMR

Точка остановки потока
Да
Обработчик прерываний
Нет
Обработчик сигналов
Нет
В потоке
Да

Тематические ссылки:

delay(), errno, clock_getres(), clock_gettime(), clock_settime(), sleep(), timer_create(), timer_delete(), timer_gettime(), timer_settime(), struct timespec, usleep()




Предыдущий раздел: Описание API системной библиотеки