1sem_timedwait(3C)        Standard C Library Functions        sem_timedwait(3C)
2
3
4

NAME

6       sem_timedwait, sem_reltimedwait_np - lock a semaphore
7

SYNOPSIS

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
16       int sem_reltimedwait_np(sem_t *restrict sem,
17            const struct timespec *restrict rel_timeout);
18
19

DESCRIPTION

21       The  sem_timedwait()  function locks the semaphore referenced by sem as
22       in the sem_wait(3C) function.  However,  if  the  semaphore  cannot  be
23       locked without waiting for another process or thread to unlock the sem‐
24       aphore by performing a sem_post(3C) function, this wait  is  terminated
25       when the specified timeout expires.
26
27
28       The  sem_reltimedwait_np() function is identical to the sem_timedwait()
29       function, except that the timeout  is  specified  as  a  relative  time
30       interval.
31
32
33       For  sem_timedwait(), the timeout expires when the absolute time speci‐
34       fied by abs_timeout passes, as measured  by  the  CLOCK_REALTIME  clock
35       (that  is, when the value of that clock equals or exceeds abs_timeout),
36       or if the absolute time  specified  by  abs_timeout  has  already  been
37       passed at the time of the call.
38
39
40       For  sem_reltimedwait_np(),  the timeout expires when the time interval
41       specified by rel_timeout passes,  as  measured  by  the  CLOCK_REALTIME
42       clock,  or if the time interval specified by rel_timeout is negative at
43       the time of the call.
44
45
46       The resolution of the timeout is the resolution of  the  CLOCK_REALTIME
47       clock. The timespec data type is defined as a structure in the <time.h>
48       header.
49
50
51       Under no circumstance does the function fail with a timeout if the sem‐
52       aphore  can be locked immediately. The validity of the abs_timeout need
53       not be checked if the semaphore can be locked immediately.
54

RETURN VALUES

56       The sem_timedwait() and sem_reltimedwait_np() functions return 0 if the
57       calling  process successfully performed the semaphore lock operation on
58       the semaphore designated by sem. If  the  call  was  unsuccessful,  the
59       state  of the semaphore is be unchanged and the function returns -1 and
60       sets errno to indicate the error.
61

ERRORS

63       The sem_timedwait() and sem_reltimedwait_np() functions will fail if:
64
65       EINVAL       The sem argument does not refer to a valid semaphore.
66
67
68       EINVAL       The process or thread would have blocked, and the  timeout
69                    parameter  specified  a  nanoseconds field value less than
70                    zero or greater than or equal to 1,000 million.
71
72
73       ETIMEDOUT    The semaphore could not be  locked  before  the  specified
74                    timeout expired.
75
76
77
78       The sem_timedwait() and sem_reltimedwait_np() functions may fail if:
79
80       EDEADLK    A deadlock condition was detected.
81
82
83       EINTR      A signal interrupted this function.
84
85

ATTRIBUTES

87       See attributes(5) for descriptions of the following attributes:
88
89
90
91
92       ┌─────────────────────────────┬─────────────────────────────┐
93       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
94       ├─────────────────────────────┼─────────────────────────────┤
95       │Interface Stability          │Commmitted                   │
96       ├─────────────────────────────┼─────────────────────────────┤
97       │MT-Level                     │MT-Safe                      │
98       ├─────────────────────────────┼─────────────────────────────┤
99       │Standard                     │See below.                   │
100       └─────────────────────────────┴─────────────────────────────┘
101
102
103       For sem_timedwait(), see standards(5).
104

SEE ALSO

106       semctl(2),   semget(2),   semop(2),   time(2),  sem_post(3C),  sem_try‐
107       wait(3C)sem_wait(3C), attributes(5), standards(5)
108
109
110
111SunOS 5.11                        5 Feb 2008                 sem_timedwait(3C)
Impressum