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