2 .\" Copyright (C) 2010 The DragonFly Project. All rights reserved.
3 .\" Copyright (C) 2000 Jason Evans <jasone@FreeBSD.org>. 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(s), this list of conditions and the following disclaimer as
10 .\" the first lines of this file unmodified other than the possible
11 .\" addition of one or more copyright notices.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\" notice(s), this list of conditions and the following disclaimer in the
14 .\" documentation and/or other materials provided with the distribution.
16 .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
17 .\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 .\" DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
20 .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 .\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 .\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 .\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
28 .\" $FreeBSD: src/share/man/man9/condvar.9,v 1.11 2004/11/08 18:15:11 jhb Exp $
40 .Nm cv_timedwait_sig ,
43 .Nm cv_mtx_timedwait ,
44 .Nm cv_mtx_timedwait_sig ,
48 .Nd kernel condition variable
54 .Fn cv_init "struct cv *cvp" "const char *desc"
56 .Fn cv_destroy "struct cv *cvp"
58 .Fn cv_wait "struct cv *cvp" "struct lock *l"
60 .Fn cv_wait_sig "struct cv *cvp" "struct lock *l"
62 .Fn cv_timedwait "struct cv *cvp" "struct lock *l" "int timo"
64 .Fn cv_timedwait_sig "struct cv *cvp" "struct lock *l" "int timo"
66 .Fn cv_mtx_wait "struct cv *cvp" "struct mtx *m"
68 .Fn cv_mtx_wait_sig "struct cv *cvp" "struct mtx *m"
70 .Fn cv_mtx_timedwait "struct cv *cvp" "struct mtx *m" "int timo"
72 .Fn cv_mtx_timedwait_sig "struct cv *cvp" "struct mtx *m" "int timo"
74 .Fn cv_signal "struct cv *cvp"
76 .Fn cv_broadcast "struct cv *cvp"
78 .Fn cv_broadcastpri "struct cv *cvp" "int pri"
80 Condition variables are used in conjunction with locks to wait for conditions
82 Condition variables are created with
86 is a pointer to space for a
90 is a pointer to a null-terminated character string that describes the condition
92 Condition variables are destroyed with
94 Threads wait on condition variables by calling
99 .Fn cv_timedwait_sig .
100 Threads unblock waiters by calling
102 to unblock one waiter, or
106 to unblock all waiters.
123 .Fn cv_timedwait_sig .
124 When a thread waits on a condition,
126 is atomically released before the thread is blocked, then atomically reacquired
127 before the function call returns.
128 All waiters must pass the same
139 unblock, their calling threads are made runnable.
145 / hz seconds before being unblocked and returning
147 otherwise, they return 0.
151 return prematurely with a value of
155 if a signal is caught, or 0 if signaled via
161 .Fn cv_mtx_wait_sig ,
162 .Fn cv_mtx_timedwait ,
164 .Fn cv_mtx_timedwait_sig
171 except that they take
175 .Sh IMPLEMENTATION NOTES
176 Condition variables exist primarily for code imported from other systems; for
182 family of functions should be used instead.
188 .Fn cv_mtx_wait_sig ,
189 .Fn cv_mtx_timedwait ,
191 .Fn cv_mtx_timedwait_sig
193 Otherwise, a non-zero error code is returned.
195 Condition variables are implemented in
196 .Pa /sys/kern/kern_condvar.c .
197 The public interface and structure is found in
198 .Pa /sys/sys/condvar.h .
205 Condition variables appeared in
208 This manual page was written by