1 .\" $NetBSD: pthread_mutexattr.3,v 1.3 2003/07/04 08:36:06 wiz Exp $
3 .\" Copyright (c) 2002 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 .\" 3. Neither the name of The NetBSD Foundation nor the names of its
14 .\" contributors may be used to endorse or promote products derived
15 .\" from this software without specific prior written permission.
16 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 .\" POSSIBILITY OF SUCH DAMAGE.
28 .\" Copyright (C) 2000 Jason Evans <jasone@FreeBSD.org>.
29 .\" All rights reserved.
31 .\" Redistribution and use in source and binary forms, with or without
32 .\" modification, are permitted provided that the following conditions
34 .\" 1. Redistributions of source code must retain the above copyright
35 .\" notice(s), this list of conditions and the following disclaimer as
36 .\" the first lines of this file unmodified other than the possible
37 .\" addition of one or more copyright notices.
38 .\" 2. Redistributions in binary form must reproduce the above copyright
39 .\" notice(s), this list of conditions and the following disclaimer in
40 .\" the documentation and/or other materials provided with the
43 .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
44 .\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
46 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
47 .\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
48 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
49 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
50 .\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
51 .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
52 .\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
53 .\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55 .\" $FreeBSD: src/lib/libpthread/man/pthread_mutexattr.3,v 1.8 2002/09/16 19:29:29 mini Exp $
57 .Dt PTHREAD_MUTEXATTR 3
60 .Nm pthread_mutexattr_destroy ,
61 .Nm pthread_mutexattr_getprioceiling ,
62 .Nm pthread_mutexattr_getprotocol ,
63 .Nm pthread_mutexattr_gettype ,
64 .Nm pthread_mutexattr_init ,
65 .Nm pthread_mutexattr_setprioceiling ,
66 .Nm pthread_mutexattr_setprotocol ,
67 .Nm pthread_mutexattr_settype
68 .Nd mutex attribute operations
70 .Fd #include <pthread.h>
72 .Fo pthread_mutexattr_destroy
73 .Fa "pthread_mutexattr_t *attr"
76 .Fo pthread_mutexattr_getprioceiling
77 .Fa "const pthread_mutexattr_t *attr"
78 .Fa "int *prioceiling"
80 .\" To match the SUS, this should be:
82 .\" .Fo pthread_mutexattr_getprioceiling
83 .\" .Fa "pthread_mutexattr_t *restrict attr"
84 .\" .Fa "int *restrict prioceiling"
87 .Fo pthread_mutexattr_getprotocol
88 .Fa "const pthread_mutexattr_t *attr"
91 .\" To match the SUS, this should be:
93 .\" .Fo pthread_mutexattr_getprotocol
94 .\" .Fa "pthread_mutexattr_t *restrict attr"
95 .\" .Fa "int *restrict protocol"
98 .Fo pthread_mutexattr_gettype
99 .Fa "const pthread_mutexattr_t *attr"
102 .\" To match the SUS, this should be:
104 .\" .Fo pthread_mutexattr_gettype
105 .\" .Fa "pthread_mutexattr_t *restrict attr"
106 .\" .Fa "int *restrict type"
109 .Fo pthread_mutexattr_init
110 .Fa "pthread_mutexattr_t *attr"
113 .Fo pthread_mutexattr_setprioceiling
114 .Fa "pthread_mutexattr_t *attr"
115 .Fa "int prioceiling"
118 .Fo pthread_mutexattr_setprotocol
119 .Fa "pthread_mutexattr_t *attr"
123 .Fo pthread_mutexattr_settype
124 .Fa "pthread_mutexattr_t *attr"
128 Mutex attributes are used to specify parameters to
129 .Fn pthread_mutex_init .
130 One attribute object can be used in multiple calls to
131 .Fn pthread_mutex_init ,
132 with or without modifications between calls.
135 .Fn pthread_mutexattr_init
138 with all of the default mutex attributes.
141 .Fn pthread_mutexattr_destroy
146 .Fn pthread_mutexattr_settype
147 function sets the mutex type value of the attribute. Valid mutex types are:
148 .Dv PTHREAD_MUTEX_NORMAL ,
149 .Dv PTHREAD_MUTEX_ERRORCHECK ,
150 .Dv PTHREAD_MUTEX_RECURSIVE ,
152 .Dv PTHREAD_MUTEX_DEFAULT .
153 The default mutex type for
154 .Fn pthread_mutexaddr_init
156 .Dv PTHREAD_MUTEX_DEFAULT .
158 .Dv PTHREAD_MUTEX_NORMAL
159 mutexes do not check for usage errors.
160 .Dv PTHREAD_MUTEX_NORMAL
161 mutexes will deadlock if reentered, and result in undefined behavior if a
162 locked mutex is unlocked by another thread. Attempts to unlock an already
164 .Dv PTHREAD_MUTEX_NORMAL
165 mutex will result in undefined behavior.
167 .Dv PTHREAD_MUTEX_ERRORCHECK
168 mutexes do check for usage errors.
169 If an attempt is made to relock a
170 .Dv PTHREAD_MUTEX_ERRORCHECK
171 mutex without first dropping the lock, an error will be returned.
172 If a thread attempts to unlock a
173 .Dv PTHREAD_MUTEX_ERRORCHECK
174 mutex that is locked by another thread, an error will be returned. If a
175 thread attempts to unlock a
176 .Dv PTHREAD_MUTEX_ERRORCHECK
177 thread that is unlocked, an error will be returned.
179 .Dv PTHREAD_MUTEX_RECURSIVE
180 mutexes allow recursive locking.
181 An attempt to relock a
182 .Dv PTHREAD_MUTEX_RECURSIVE
183 mutex that is already locked by the same thread succeeds. An equivalent
185 .Xr pthread_mutex_unlock 3
186 calls are needed before the mutex will wake another thread waiting on this
187 lock. If a thread attempts to unlock a
188 .Dv PTHREAD_MUTEX_RECURSIVE
189 mutex that is locked by another thread, an error will be returned. If a thread attemps to unlock a
190 .Dv PTHREAD_MUTEX_RECURSIVE
191 thread that is unlocked, an error will be returned.
193 .Dv PTHREAD_MUTEX_DEFAULT
194 mutexes result in undefined behavior if reentered.
196 .Dv PTHREAD_MUTEX_DEFAULT
197 mutex locked by another thread will result in undefined behavior. Attempts to unlock an already
199 .Dv PTHREAD_MUTEX_DEFAULT
200 mutex will result in undefined behavior.
202 .Fn pthread_mutexattr_gettype
203 functions copy the type value of the attribute to the location pointed to by the second parameter.
206 .Fn pthread_mutexattr_set*
207 functions set the attribute that corresponds to each function name.
210 .Fn pthread_mutexattr_get*
211 functions copy the value of the attribute that corresponds to each function name
212 to the location pointed to by the second function parameter.
214 If successful, these functions return 0.
215 Otherwise, an error number is returned to indicate the error.
217 .Fn pthread_mutexattr_init
224 .Fn pthread_mutexattr_destroy
232 .Fn pthread_mutexattr_setprioceiling
242 .Fn pthread_mutexattr_getprioceiling
250 .Fn pthread_mutexattr_setprotocol
260 .Fn pthread_mutexattr_getprotocol
268 .Fn pthread_mutexattr_settype
278 .Fn pthread_mutexattr_gettype
286 .Xr pthread_mutex_init 3
288 .Fn pthread_mutexattr_init
290 .Fn pthread_mutexattr_destroy
294 .Fn pthread_mutexattr_setprioceiling ,
295 .Fn pthread_mutexattr_getprioceiling ,
296 .Fn pthread_mutexattr_setprotocol ,
297 .Fn pthread_mutexattr_getprotocol ,
298 .Fn pthread_mutexattr_settype ,
300 .Fn pthread_mutexattr_gettype