9103 opengroup acknowledgement should be properly formatted in man pages
[unleashed.git] / usr / src / man / man3c / pthread_cond_wait.3c
blob7133cbc6994ff3b482d4c78e332833fac7bf8ae6
1 .\"
2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
3 .\" permission to reproduce portions of its copyrighted documentation.
4 .\" Original documentation from The Open Group can be obtained online at
5 .\" http://www.opengroup.org/bookstore/.
6 .\"
7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 .\" Group, have given us permission to reprint portions of their
9 .\" documentation.
10 .\"
11 .\" In the following statement, the phrase ``this text'' refers to portions
12 .\" of the system documentation.
13 .\"
14 .\" Portions of this text are reprinted and reproduced in electronic form
15 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
16 .\" Standard for Information Technology -- Portable Operating System
17 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
18 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
19 .\" Engineers, Inc and The Open Group.  In the event of any discrepancy
20 .\" between these versions and the original IEEE and The Open Group
21 .\" Standard, the original IEEE and The Open Group Standard is the referee
22 .\" document.  The original Standard can be obtained online at
23 .\" http://www.opengroup.org/unix/online.html.
24 .\"
25 .\" This notice shall appear on any product containing this material.
26 .\"
27 .\" The contents of this file are subject to the terms of the
28 .\" Common Development and Distribution License (the "License").
29 .\" You may not use this file except in compliance with the License.
30 .\"
31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32 .\" or http://www.opensolaris.org/os/licensing.
33 .\" See the License for the specific language governing permissions
34 .\" and limitations under the License.
35 .\"
36 .\" When distributing Covered Code, include this CDDL HEADER in each
37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
38 .\" If applicable, add the following below this CDDL HEADER, with the
39 .\" fields enclosed by brackets "[]" replaced with your own identifying
40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
41 .\"
42 .\"
43 .\" Copyright 1991, 1992, 1994, The X/Open Company Ltd.
44 .\" Copyright (c) 2001, The IEEE and The Open Group.  All Rights Reserved.
45 .\" Copyright (c) 2008, Sun Microsystems, Inc.  All Rights Reserved.
46 .\"
47 .TH PTHREAD_COND_WAIT 3C "Nov 11, 2008"
48 .SH NAME
49 pthread_cond_wait, pthread_cond_timedwait, pthread_cond_reltimedwait_np \- wait
50 on a condition
51 .SH SYNOPSIS
52 .LP
53 .nf
54 cc -mt [ \fIflag\fR... ] \fIfile\fR... -lpthread [ \fIlibrary\fR... ]
55 #include <pthread.h>
57 \fBint\fR \fBpthread_cond_wait\fR(\fBpthread_cond_t *restrict\fR \fIcond\fR,
58      \fBpthread_mutex_t *restrict\fR \fImutex\fR);
59 .fi
61 .LP
62 .nf
63 \fBint\fR \fBpthread_cond_timedwait\fR(\fBpthread_cond_t *restrict\fR \fIcond\fR,
64      \fBpthread_mutex_t *restrict\fR \fImutex\fR,
65      \fBconst struct timespec *restrict\fR \fIabstime\fR);
66 .fi
68 .LP
69 .nf
70 \fBint\fR \fBpthread_cond_reltimedwait_np\fR(\fBpthread_cond_t *\fR\fIcond\fR,
71      \fBpthread_mutex_t *\fR\fImutex\fR, \fBconst struct timespec *\fR\fIreltime\fR);
72 .fi
74 .SH DESCRIPTION
75 .sp
76 .LP
77 The \fBpthread_cond_wait()\fR, \fBpthread_cond_timedwait()\fR, and
78 \fBpthread_cond_reltimedwait_np()\fR functions are used to block on a condition
79 variable. They are called with \fImutex\fR locked by the calling thread or
80 undefined behavior will result.
81 .sp
82 .LP
83 These functions atomically release \fImutex\fR and cause the calling thread to
84 block on the condition variable \fIcond\fR. Atomically here means ``atomically
85 with respect to access by another  thread to the mutex and then the condition
86 variable." That is, if another thread is able to acquire the mutex after the
87 about-to-block thread has released it, then a subsequent call to
88 \fBpthread_cond_signal()\fR or \fBpthread_cond_broadcast()\fR in that thread
89 behaves as if it were issued after the about-to-block thread has blocked.
90 .sp
91 .LP
92 Upon successful return, the mutex has been locked and is owned by the calling
93 thread. If mutex is a robust mutex where an owner terminated while holding the
94 lock and the state is recoverable, the mutex is acquired even though the
95 function returns an error value.
96 .sp
97 .LP
98 When using condition variables there is always a boolean predicate, an
99 invariant, associated with each condition wait that must be true before the
100 thread should proceed. Spurious wakeups from the \fBpthread_cond_wait()\fR,
101 \fBpthread_cond_timedwait()\fR, or \fBpthread_cond_reltimedwait_np()\fR
102 functions could occur. Since the return from \fBpthread_cond_wait()\fR,
103 \fBpthread_cond_timedwait()\fR, or \fBpthread_cond_reltimedwait_np()\fR does
104 not imply anything about the value of this predicate, the predicate should
105 always be reevaluated.
108 The order in which blocked threads are awakened by \fBpthread_cond_signal()\fR
109 or \fBpthread_cond_broadcast()\fR is determined by the scheduling policy. See
110 \fBpthreads\fR(5).
113 The effect of using more than one mutex for concurrent
114 \fBpthread_cond_wait()\fR, \fBpthread_cond_timedwait()\fR, or
115 \fBpthread_cond_reltimedwait_np()\fR operations on the same condition variable
116 will result in undefined behavior.
119 A condition wait (whether timed or not) is a cancellation point. When the
120 cancelability enable state of a thread is set to \fBPTHREAD_CANCEL_DEFERRED\fR,
121 a side effect of acting upon a cancellation request while in a condition wait
122 is that the mutex is reacquired before calling the first cancellation cleanup
123 handler.
126 A thread that has been unblocked because it has been canceled while blocked in
127 a call to \fBpthread_cond_wait()\fR or \fBpthread_cond_timedwait()\fR does not
128 consume any condition signal that may be directed concurrently at the condition
129 variable if there are other threads blocked on the condition variable.
132 The \fBpthread_cond_timedwait()\fR function is the same as
133 \fBpthread_cond_wait()\fR except that an error is returned if the absolute time
134 specified by \fIabstime\fR passes (that is, system time equals or exceeds
135 \fIabstime\fR) before the condition \fIcond\fR is signaled or broadcast, or if
136 the absolute time specified by \fIabstime\fR has already been passed at the
137 time of the call. The \fIabstime\fR argument is of type \fBstruct timespec\fR,
138 defined in \fBtime.h\fR(3HEAD). When such time-outs occur,
139 \fBpthread_cond_timedwait()\fR will nonetheless release and reacquire the mutex
140 referenced by \fImutex\fR. The function \fBpthread_cond_timedwait()\fR is also
141 a cancellation point.
144 The \fBpthread_cond_reltimedwait_np()\fR function is a non-standard extension
145 provided by the Solaris version of POSIX threads as indicated by the
146 ``\fB_np\fR'' (non-portable) suffix. The \fBpthread_cond_reltimedwait_np()\fR
147 function is the same as \fBpthread_cond_timedwait()\fR except that the
148 \fIreltime\fR argument specifies a non-negative time relative to the current
149 system time rather than an absolute time. The \fIreltime\fR argument is of type
150 \fBstruct timespec\fR, defined in \fBtime.h\fR(3HEAD). An error value is
151 returned if the relative time passes (that is, system time equals or exceeds
152 the starting system time plus the relative time) before the condition
153 \fIcond\fR is signaled or broadcast.  When such timeouts occur,
154 \fBpthread_cond_reltimedwait_np()\fR releases and reacquires the mutex
155 referenced by \fImutex\fR.  The \fBpthread_cond_reltimedwait_np()\fR function
156 is also a cancellation point.
159 If a signal is delivered to a thread waiting for a condition variable, upon
160 return from the signal handler the thread resumes waiting for the condition
161 variable as if it was not interrupted, or it returns \fB0\fR due to spurious
162 wakeup.
163 .SH RETURN VALUES
166 Except in the case of \fBETIMEDOUT\fR, \fBEOWNERDEAD\fR, or
167 \fBENOTRECOVERABLE\fR, all of these error checks act as if they were performed
168 immediately at the beginning of processing for the function and cause an error
169 return, in effect, prior to modifying the state of the mutex specified by
170 \fImutex\fR or the condition variable specified by \fIcond\fR.
173 Upon successful completion, \fB0\fR is returned. Otherwise, an error value is
174 returned to indicate the error.
175 .SH ERRORS
178 These functions will fail if:
180 .ne 2
182 \fB\fBEPERM\fR\fR
184 .RS 9n
185 The mutex type is \fBPTHREAD_MUTEX_ERRORCHECK\fR or the mutex is a robust
186 mutex, and the current thread does not own the mutex.
191 The  \fBpthread_cond_timedwait()\fR function will fail if:
193 .ne 2
195 \fB\fBETIMEDOUT\fR\fR
197 .RS 13n
198 The absolute time specified by \fIabstime\fR to \fBpthread_cond_timedwait()\fR
199 has passed.
204 The \fBpthread_cond_reltimedwait_np()\fR function will fail if:
206 .ne 2
208 \fB\fBEINVAL\fR\fR
210 .RS 13n
211 The value specified by \fIreltime\fR is invalid.
215 .ne 2
217 \fB\fBETIMEDOUT\fR\fR
219 .RS 13n
220 The relative time specified by \fIreltime\fR to
221 \fBpthread_cond_reltimedwait_np()\fR has passed.
226 These functions may fail if:
228 .ne 2
230 \fB\fBEINVAL\fR\fR
232 .RS 10n
233 The value specified by \fIcond\fR, \fImutex\fR, \fIabstime\fR, or \fIreltime\fR
234 is invalid.
238 .ne 2
240 \fB\fBEINVAL\fR\fR
242 .RS 10n
243 Different mutexes were supplied for concurrent operations on the same condition
244 variable.
249 If the mutex specified by \fImutex\fR is a robust mutex (initialized with the
250 robustness attribute \fBPTHREAD_MUTEX_ROBUST\fR), the
251 \fBpthread_cond_wait()\fR, \fBpthread_cond_timedwait()\fR, and
252 \fBpthread_cond_reltimedwait_np()\fR functions will, under the specified
253 conditions, return the following error values.  For complete information, see
254 the \fBpthread_mutex_lock\fR(3C) and \fBpthread_mutexattr_setrobust\fR(3C)
255 manual pages.
257 .ne 2
259 \fB\fBEOWNERDEAD\fR\fR
261 .RS 19n
262 The last owner of this mutex died while holding the mutex, leaving the state it
263 was protecting possibly inconsistent. The mutex is now owned by the caller.
267 .ne 2
269 \fB\fBENOTRECOVERABLE\fR\fR
271 .RS 19n
272 The mutex was protecting state that has now been left irrecoverable. The mutex
273 has not been acquired.
276 .SH ATTRIBUTES
279 See \fBattributes\fR(5) for descriptions of the following attributes:
284 box;
285 c | c
286 l | l .
287 ATTRIBUTE TYPE  ATTRIBUTE VALUE
289 Interface Stability     Standard
291 MT-Level        MT-Safe
294 .SH SEE ALSO
297 \fBpthread_cond_signal\fR(3C), \fBpthread_cond_broadcast\fR(3C),
298 \fBpthread_mutex_lock\fR(3C), \fBpthread_mutexattr_getrobust\fR(3C),
299 \fBtime.h\fR(3HEAD), \fBattributes\fR(5), \fBcondition\fR(5),
300 \fBpthreads\fR(5), \fBstandards\fR(5)