1SEM_TIMEDWAIT(P) POSIX Programmer's Manual SEM_TIMEDWAIT(P)
2
3
4
6 sem_timedwait - lock a semaphore (ADVANCED REALTIME)
7
9 #include <semaphore.h>
10 #include <time.h>
11
12 int sem_timedwait(sem_t *restrict sem,
13 const struct timespec *restrict abs_timeout);
14
15
17 The sem_timedwait() function shall lock the semaphore referenced by sem
18 as in the sem_wait() function. However, if the semaphore cannot be
19 locked without waiting for another process or thread to unlock the sem‐
20 aphore by performing a sem_post() function, this wait shall be termi‐
21 nated when the specified timeout expires.
22
23 The timeout shall expire when the absolute time specified by abs_time‐
24 out passes, as measured by the clock on which timeouts are based (that
25 is, when the value of that clock equals or exceeds abs_timeout), or if
26 the absolute time specified by abs_timeout has already been passed at
27 the time of the call.
28
29 If the Timers option is supported, the timeout shall be based on the
30 CLOCK_REALTIME clock. If the Timers option is not supported, the time‐
31 out shall be based on the system clock as returned by the time() func‐
32 tion. The resolution of the timeout shall be the resolution of the
33 clock on which it is based. The timespec data type is defined as a
34 structure in the <time.h> header.
35
36 Under no circumstance shall the function fail with a timeout if the
37 semaphore can be locked immediately. The validity of the abs_timeout
38 need not be checked if the semaphore can be locked immediately.
39
41 The sem_timedwait() function shall return zero if the calling process
42 successfully performed the semaphore lock operation on the semaphore
43 designated by sem. If the call was unsuccessful, the state of the sema‐
44 phore shall be unchanged, and the function shall return a value of -1
45 and set errno to indicate the error.
46
48 The sem_timedwait() function shall fail if:
49
50 EINVAL The sem argument does not refer to a valid semaphore.
51
52 EINVAL The process or thread would have blocked, and the abs_timeout
53 parameter specified a nanoseconds field value less than zero or
54 greater than or equal to 1000 million.
55
56 ETIMEDOUT
57 The semaphore could not be locked before the specified timeout
58 expired.
59
60
61 The sem_timedwait() function may fail if:
62
63 EDEADLK
64 A deadlock condition was detected.
65
66 EINTR A signal interrupted this function.
67
68
69 The following sections are informative.
70
72 None.
73
75 Applications using these functions may be subject to priority inver‐
76 sion, as discussed in the Base Definitions volume of
77 IEEE Std 1003.1-2001, Section 3.285, Priority Inversion.
78
79 The sem_timedwait() function is part of the Semaphores and Timeouts
80 options and need not be provided on all implementations.
81
83 None.
84
86 None.
87
89 sem_post() , sem_trywait() , sem_wait() , semctl() , semget() , semop()
90 , time() , the Base Definitions volume of IEEE Std 1003.1-2001, <sema‐
91 phore.h>, <time.h>
92
94 Portions of this text are reprinted and reproduced in electronic form
95 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
96 -- Portable Operating System Interface (POSIX), The Open Group Base
97 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
98 Electrical and Electronics Engineers, Inc and The Open Group. In the
99 event of any discrepancy between this version and the original IEEE and
100 The Open Group Standard, the original IEEE and The Open Group Standard
101 is the referee document. The original Standard can be obtained online
102 at http://www.opengroup.org/unix/online.html .
103
104
105
106IEEE/The Open Group 2003 SEM_TIMEDWAIT(P)