1_lwp_cond_wait(2)                System Calls                _lwp_cond_wait(2)
2
3
4

NAME

6       _lwp_cond_wait, _lwp_cond_timedwait, _lwp_cond_reltimedwait - wait on a
7       condition variable
8

SYNOPSIS

10       #include <sys/lwp.h>
11
12       int _lwp_cond_wait(lwp_cond_t *cvp, lwp_mutex_t *mp);
13
14
15       int _lwp_cond_timedwait(lwp_cond_t *cvp, lwp_mutex_t *mp,
16            timestruc_t *abstime);
17
18
19       int _lwp_cond_reltimedwait(lwp_cond_t *cvp, lwp_mutex_t *mp,
20            timestruc_t *reltime);
21
22

DESCRIPTION

24       These functions are used to wait for the occurrence of a condition rep‐
25       resented  by an LWP condition variable. LWP condition variables must be
26       initialized to 0 before use.
27
28
29       The _lwp_cond_wait() function atomically releases the LWP mutex pointed
30       to by mp and causes the calling LWP to block on the LWP condition vari‐
31       able  pointed  to  by  cvp.  The  blocked  LWP  may  be   awakened   by
32       _lwp_cond_signal(2),  _lwp_cond_broadcast(2),  or  when  interrupted by
33       delivery of a signal. Any change in value  of  a  condition  associated
34       with  the  condition  variable  cannot  be  inferred  by  the return of
35       _lwp_cond_wait() and any such condition must be re-evaluated.
36
37
38       The _lwp_cond_timedwait()  function  is  similar  to  _lwp_cond_wait(),
39       except  that the calling LWP will not block past the time of day speci‐
40       fied by abstime. If the time  of  day  becomes  greater  than  abstime,
41       _lwp_cond_timedwait() returns with the error code ETIME.
42
43
44       The  _lwp_cond_reltimedwait()  function is similar to _lwp_cond_wait(),
45       except that the calling LWP will not block past the relative time spec‐
46       ified  by reltime. If the time of day becomes greater than the starting
47       time of day plus reltime,  _lwp_cond_reltimedwait()  returns  with  the
48       error code ETIME.
49
50
51       The  _lwp_cond_wait(),  _lwp_cond_timedwait(),  and _lwp_cond_reltimed‐
52       wait() functions always return with the mutex locked and owned  by  the
53       calling lightweight process.
54

RETURN VALUES

56       Upon  successful  completion, 0 is returned. A non-zero value indicates
57       an error.
58

ERRORS

60       If any of the  following  conditions  are  detected,  _lwp_cond_wait(),
61       _lwp_cond_timedwait(), and _lwp_cond_reltimedwait() fail and return the
62       corresponding value:
63
64       EINVAL    The cvp argument points to an invalid LWP condition  variable
65                 or the mp argument points to an invalid LWP mutex.
66
67
68       EFAULT    The  mp,  cvp,  or  abstime  argument  points  to  an illegal
69                 address.
70
71
72
73       If  any  of   the   following   conditions   occur,   _lwp_cond_wait(),
74       _lwp_cond_timedwait(), and _lwp_cond_reltimedwait() fail and return the
75       corresponding value:
76
77       EINTR    The call was interrupted by a signal or fork(2).
78
79
80
81       If any of the following  conditions  occur,  _lwp_cond_timedwait()  and
82       _lwp_cond_reltimedwait() fail and return the corresponding value:
83
84       ETIME    The time specified inabstime or reltime has passed.
85
86

EXAMPLES

88       Example 1 Use the _lwp_cond_wait() function in a loop testing some con‐
89       dition.
90
91
92       The _lwp_cond_wait() function is normally used in a loop  testing  some
93       condition, as follows:
94
95
96         lwp_mutex_t m;
97         lwp_cond_t cv;
98         int cond;
99         (void) _lwp_mutex_lock(&m);
100         while (cond == FALSE) {
101                 (void) _lwp_cond_wait(&cv, &m);
102         }
103         (void) _lwp_mutex_unlock(&m);
104
105
106       Example 2 Use the _lwp_cond_timedwait() function in a loop testing some
107       condition.
108
109
110       The _lwp_cond_timedwait() function is also  normally  used  in  a  loop
111       testing some condition. It uses an absolute timeout value as follows:
112
113
114         timestruc_t to;
115         lwp_mutex_t m;
116         lwp_cond_t cv;
117         int cond, err;
118         (void) _lwp_mutex_lock(&m);
119         to.tv_sec = time(NULL) + TIMEOUT;
120         to.tv_nsec = 0;
121         while (cond == FALSE) {
122                 err = _lwp_cond_timedwait(&cv, &m, &to);
123                 if (err == ETIME) {
124                         /* timeout, do something */
125                         break;
126                 SENDwhom}
127         }
128         (void) _lwp_mutex_unlock(&m);
129
130
131
132       This  example  sets  a  bound  on  the  total wait time even though the
133       _lwp_cond_timedwait() may return several times  due  to  the  condition
134       being signalled or the wait being interrupted.
135
136
137       Example  3  Use the _lwp_cond_reltimedwait() function in a loop testing
138       some condition.
139
140
141       The _lwp_cond_reltimedwait() function is also normally used in  a  loop
142       testing some condition. It uses a relative timeout value as follows:
143
144
145         timestruc_t to;
146         lwp_mutex_t m;
147         lwp_cond_t cv;
148         int cond, err;
149         (void) _lwp_mutex_lock(&m);
150         while (cond == FALSE) {
151                 to.tv_sec = TIMEOUT;
152                 to.tv_nsec = 0;
153                 err = _lwp_cond_reltimedwait(&cv, &m, &to);
154                 if (err == ETIME) {
155                         /* timeout, do something */
156                         break;
157                 }
158         }
159         (void) _lwp_mutex_unlock(&m);
160
161

SEE ALSO

163       _lwp_cond_broadcast(2),        _lwp_cond_signal(2),       _lwp_kill(2),
164       _lwp_mutex_lock(2), fork(2), kill(2)
165
166
167
168SunOS 5.11                        13 Apr 2001                _lwp_cond_wait(2)
Impressum