1 .\" $NetBSD: pthread_cond_wait.3,v 1.12 2009/01/11 02:46:48 christos Exp $
3 .\" Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
13 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
14 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
15 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
17 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23 .\" POSSIBILITY OF SUCH DAMAGE.
25 .\" Copyright (c) 1997 Brian Cully <shmit@kublai.com>
26 .\" All rights reserved.
28 .\" Redistribution and use in source and binary forms, with or without
29 .\" modification, are permitted provided that the following conditions
31 .\" 1. Redistributions of source code must retain the above copyright
32 .\" notice, this list of conditions and the following disclaimer.
33 .\" 2. Redistributions in binary form must reproduce the above copyright
34 .\" notice, this list of conditions and the following disclaimer in the
35 .\" documentation and/or other materials provided with the distribution.
36 .\" 3. Neither the name of the author nor the names of any co-contributors
37 .\" may be used to endorse or promote products derived from this software
38 .\" without specific prior written permission.
40 .\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
41 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
44 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52 .\" $FreeBSD: src/lib/libpthread/man/pthread_cond_wait.3,v 1.16 2002/09/16 19:29:28 mini Exp $
55 .Dt PTHREAD_COND_WAIT 3
58 .Nm pthread_cond_wait ,
59 .Nm pthread_cond_timedwait
60 .Nd wait on a condition variable
66 .Fn pthread_cond_wait "pthread_cond_t * restrict cond" "pthread_mutex_t * restrict mutex"
68 .Fn pthread_cond_timedwait "pthread_cond_t * restrict cond" "pthread_mutex_t * restrict mutex" "const struct timespec * restrict abstime"
72 function atomically blocks the current thread waiting on the condition
75 and unlocks the mutex specified by
77 The waiting thread unblocks after another thread calls
78 .Xr pthread_cond_signal 3 ,
80 .Xr pthread_cond_broadcast 3
81 with the same condition variable.
82 The current thread holds the lock on
89 .Fn pthread_cond_timedwait
90 function atomically blocks the current thread waiting on the condition
93 and unlocks the mutex specified by
95 The waiting thread unblocks after another thread calls
96 .Xr pthread_cond_signal 3 ,
98 .Xr pthread_cond_broadcast 3
99 with the same condition variable, or if the system time reaches the
104 .Fn pthread_cond_wait
106 .Fn pthread_cond_timedwait
107 may wake up spontaneously, without a call to
108 .Xr pthread_cond_signal 3
110 .Xr pthread_cond_broadcast 3 .
111 The caller should prepare for this by invoking
112 .Fn pthread_cond_wait
114 .Fn pthread_cond_timedwait
115 within a predicate loop that tests whether the thread should proceed.
118 .Fn pthread_cond_wait
120 .Fn pthread_cond_timedwait ,
121 a temporary binding is established between the condition variable
126 The same mutex must be held while calling
127 .Fn pthread_cond_broadcast
129 .Fn pthread_cond_signal
132 Additionally, the same mutex must be used for concurrent calls to
133 .Fn pthread_cond_wait
135 .Fn pthread_cond_timedwait .
136 Only when a condition variable is known to be quiescent may an application
137 change the mutex associated with it.
138 In this implementation, none of the functions enforce this requirement, but
139 if the mutex is not held or independent mutexes are used the resulting
140 behaviour is undefined.
143 .Fn pthread_cond_wait
145 .Fn pthread_cond_timedwait
146 functions will return zero.
147 Otherwise an error number will be returned to
150 .Fn pthread_cond_wait
154 The value specified by
156 or the value specified by
161 .Fn pthread_cond_timedwait
165 The system time has reached or exceeded the time specified in
169 .Fn pthread_cond_timedwait
173 The value specified by
181 .Fn pthread_cond_wait
183 .Fn pthread_cond_timedwait
187 The value specified by
189 is not locked in condition wait.
192 .Xr pthread_cond_broadcast 3 ,
193 .Xr pthread_cond_destroy 3 ,
194 .Xr pthread_cond_init 3 ,
195 .Xr pthread_cond_signal 3
197 .Fn pthread_cond_wait
199 .Fn pthread_cond_timedwait