1SEM_TIMEDWAIT(3P)          POSIX Programmer's Manual         SEM_TIMEDWAIT(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       sem_timedwait - lock a semaphore (ADVANCED REALTIME)
13

SYNOPSIS

15       #include <semaphore.h>
16       #include <time.h>
17
18       int sem_timedwait(sem_t *restrict sem,
19              const struct timespec *restrict abs_timeout);
20
21

DESCRIPTION

23       The sem_timedwait() function shall lock the semaphore referenced by sem
24       as  in  the  sem_wait()  function.  However, if the semaphore cannot be
25       locked without waiting for another process or thread to unlock the sem‐
26       aphore  by  performing a sem_post() function, this wait shall be termi‐
27       nated when the specified timeout expires.
28
29       The timeout shall expire when the absolute time specified by  abs_time‐
30       out  passes, as measured by the clock on which timeouts are based (that
31       is, when the value of that clock equals or exceeds abs_timeout), or  if
32       the  absolute  time specified by abs_timeout has already been passed at
33       the time of the call.
34
35       If the Timers option is supported, the timeout shall be  based  on  the
36       CLOCK_REALTIME  clock. If the Timers option is not supported, the time‐
37       out shall be based on the system clock as returned by the time()  func‐
38       tion.  The  resolution  of  the  timeout shall be the resolution of the
39       clock on which it is based. The timespec data  type  is  defined  as  a
40       structure in the <time.h> header.
41
42       Under  no  circumstance  shall  the function fail with a timeout if the
43       semaphore can be locked immediately. The validity  of  the  abs_timeout
44       need not be checked if the semaphore can be locked immediately.
45

RETURN VALUE

47       The  sem_timedwait()  function shall return zero if the calling process
48       successfully performed the semaphore lock operation  on  the  semaphore
49       designated by sem. If the call was unsuccessful, the state of the sema‐
50       phore shall be unchanged, and the function shall return a value  of  -1
51       and set errno to indicate the error.
52

ERRORS

54       The sem_timedwait() function shall fail if:
55
56       EINVAL The sem argument does not refer to a valid semaphore.
57
58       EINVAL The  process  or  thread would have blocked, and the abs_timeout
59              parameter specified a nanoseconds field value less than zero  or
60              greater than or equal to 1000 million.
61
62       ETIMEDOUT
63              The  semaphore  could not be locked before the specified timeout
64              expired.
65
66
67       The sem_timedwait() function may fail if:
68
69       EDEADLK
70              A deadlock condition was detected.
71
72       EINTR  A signal interrupted this function.
73
74
75       The following sections are informative.
76

EXAMPLES

78       None.
79

APPLICATION USAGE

81       Applications using these functions may be subject  to  priority  inver‐
82       sion,    as    discussed    in   the   Base   Definitions   volume   of
83       IEEE Std 1003.1-2001, Section 3.285, Priority Inversion.
84
85       The sem_timedwait() function is part of  the  Semaphores  and  Timeouts
86       options and need not be provided on all implementations.
87

RATIONALE

89       None.
90

FUTURE DIRECTIONS

92       None.
93

SEE ALSO

95       sem_post(),  sem_trywait(),  sem_wait(),  semctl(),  semget(), semop(),
96       time(), the Base Definitions  volume  of  IEEE Std 1003.1-2001,  <sema‐
97       phore.h>, <time.h>
98
100       Portions  of  this text are reprinted and reproduced in electronic form
101       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
102       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
103       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
104       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
105       event of any discrepancy between this version and the original IEEE and
106       The  Open Group Standard, the original IEEE and The Open Group Standard
107       is the referee document. The original Standard can be  obtained  online
108       at http://www.opengroup.org/unix/online.html .
109
110
111
112IEEE/The Open Group                  2003                    SEM_TIMEDWAIT(3P)
Impressum