]> git.saurik.com Git - apple/libc.git/blame - pthreads/pthread_mutexattr.3
Libc-763.13.tar.gz
[apple/libc.git] / pthreads / pthread_mutexattr.3
CommitLineData
9385eb3d
A
1.\" $NetBSD: pthread_mutexattr.3,v 1.3 2003/07/04 08:36:06 wiz Exp $
2.\"
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
7.\" are met:
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.
27.\"
5b2abdfb
A
28.\" Copyright (C) 2000 Jason Evans <jasone@FreeBSD.org>.
29.\" All rights reserved.
30.\"
31.\" Redistribution and use in source and binary forms, with or without
32.\" modification, are permitted provided that the following conditions
33.\" are met:
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
41.\" distribution.
42.\"
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.
54.\"
9385eb3d
A
55.\" $FreeBSD: src/lib/libpthread/man/pthread_mutexattr.3,v 1.8 2002/09/16 19:29:29 mini Exp $
56.Dd January 30, 2003
5b2abdfb
A
57.Dt PTHREAD_MUTEXATTR 3
58.Os
59.Sh NAME
5b2abdfb 60.Nm pthread_mutexattr_destroy ,
5b2abdfb 61.Nm pthread_mutexattr_getprioceiling ,
5b2abdfb 62.Nm pthread_mutexattr_getprotocol ,
224c7076
A
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
5b2abdfb
A
68.Nd mutex attribute operations
69.Sh SYNOPSIS
70.Fd #include <pthread.h>
71.Ft int
224c7076
A
72.Fo pthread_mutexattr_destroy
73.Fa "pthread_mutexattr_t *attr"
74.Fc
5b2abdfb 75.Ft int
224c7076 76.Fo pthread_mutexattr_getprioceiling
34e8f829
A
77.Fa "const pthread_mutexattr_t *restrict attr"
78.Fa "int *restrict prioceiling"
224c7076
A
79.Fc
80.\" To match the SUS, this should be:
81.\" .Ft int
82.\" .Fo pthread_mutexattr_getprioceiling
83.\" .Fa "pthread_mutexattr_t *restrict attr"
84.\" .Fa "int *restrict prioceiling"
85.\" .Fc
5b2abdfb 86.Ft int
224c7076 87.Fo pthread_mutexattr_getprotocol
34e8f829
A
88.Fa "const pthread_mutexattr_t *restrict attr"
89.Fa "int *restrict protocol"
224c7076
A
90.Fc
91.\" To match the SUS, this should be:
92.\" .Ft int
93.\" .Fo pthread_mutexattr_getprotocol
94.\" .Fa "pthread_mutexattr_t *restrict attr"
95.\" .Fa "int *restrict protocol"
96.\" .Fc
5b2abdfb 97.Ft int
224c7076 98.Fo pthread_mutexattr_gettype
34e8f829
A
99.Fa "const pthread_mutexattr_t *restrict attr"
100.Fa "int *restrict type"
224c7076
A
101.Fc
102.\" To match the SUS, this should be:
103.\" .Ft int
104.\" .Fo pthread_mutexattr_gettype
105.\" .Fa "pthread_mutexattr_t *restrict attr"
106.\" .Fa "int *restrict type"
107.\" .Fc
5b2abdfb 108.Ft int
224c7076
A
109.Fo pthread_mutexattr_init
110.Fa "pthread_mutexattr_t *attr"
111.Fc
5b2abdfb 112.Ft int
224c7076
A
113.Fo pthread_mutexattr_setprioceiling
114.Fa "pthread_mutexattr_t *attr"
115.Fa "int prioceiling"
116.Fc
5b2abdfb 117.Ft int
224c7076
A
118.Fo pthread_mutexattr_setprotocol
119.Fa "pthread_mutexattr_t *attr"
120.Fa "int protocol"
121.Fc
5b2abdfb 122.Ft int
224c7076
A
123.Fo pthread_mutexattr_settype
124.Fa "pthread_mutexattr_t *attr"
125.Fa "int type"
126.Fc
5b2abdfb
A
127.Sh DESCRIPTION
128Mutex attributes are used to specify parameters to
129.Fn pthread_mutex_init .
130One attribute object can be used in multiple calls to
131.Fn pthread_mutex_init ,
132with or without modifications between calls.
133.Pp
134The
135.Fn pthread_mutexattr_init
136function initializes
137.Fa attr
224c7076 138with all of the default mutex attributes.
5b2abdfb
A
139.Pp
140The
141.Fn pthread_mutexattr_destroy
142function destroys
143.Fa attr .
144.Pp
145The
9385eb3d 146.Fn pthread_mutexattr_settype
224c7076 147function sets the mutex type value of the attribute. Valid mutex types are:
9385eb3d
A
148.Dv PTHREAD_MUTEX_NORMAL ,
149.Dv PTHREAD_MUTEX_ERRORCHECK ,
150.Dv PTHREAD_MUTEX_RECURSIVE ,
151and
152.Dv PTHREAD_MUTEX_DEFAULT .
153The default mutex type for
34e8f829 154.Fn pthread_mutexattr_init
9385eb3d
A
155is
156.Dv PTHREAD_MUTEX_DEFAULT .
157.Pp
224c7076 158.Dv PTHREAD_MUTEX_NORMAL
9385eb3d
A
159mutexes do not check for usage errors.
160.Dv PTHREAD_MUTEX_NORMAL
161mutexes will deadlock if reentered, and result in undefined behavior if a
162locked mutex is unlocked by another thread. Attempts to unlock an already
163unlocked
164.Dv PTHREAD_MUTEX_NORMAL
165mutex will result in undefined behavior.
166.Pp
167.Dv PTHREAD_MUTEX_ERRORCHECK
168mutexes do check for usage errors.
169If an attempt is made to relock a
170.Dv PTHREAD_MUTEX_ERRORCHECK
224c7076
A
171mutex without first dropping the lock, an error will be returned.
172If a thread attempts to unlock a
9385eb3d
A
173.Dv PTHREAD_MUTEX_ERRORCHECK
174mutex that is locked by another thread, an error will be returned. If a
224c7076 175thread attempts to unlock a
9385eb3d 176.Dv PTHREAD_MUTEX_ERRORCHECK
224c7076 177thread that is unlocked, an error will be returned.
9385eb3d
A
178.Pp
179.Dv PTHREAD_MUTEX_RECURSIVE
180mutexes allow recursive locking.
181An attempt to relock a
182.Dv PTHREAD_MUTEX_RECURSIVE
183mutex that is already locked by the same thread succeeds. An equivalent
184number of
185.Xr pthread_mutex_unlock 3
186calls are needed before the mutex will wake another thread waiting on this
187lock. If a thread attempts to unlock a
188.Dv PTHREAD_MUTEX_RECURSIVE
189mutex that is locked by another thread, an error will be returned. If a thread attemps to unlock a
190.Dv PTHREAD_MUTEX_RECURSIVE
191thread that is unlocked, an error will be returned.
192.Pp
193.Dv PTHREAD_MUTEX_DEFAULT
194mutexes result in undefined behavior if reentered.
195Unlocking a
196.Dv PTHREAD_MUTEX_DEFAULT
197mutex locked by another thread will result in undefined behavior. Attempts to unlock an already
198unlocked
199.Dv PTHREAD_MUTEX_DEFAULT
200mutex will result in undefined behavior.
201.Pp
202.Fn pthread_mutexattr_gettype
203functions copy the type value of the attribute to the location pointed to by the second parameter.
204.Pp
205The
5b2abdfb
A
206.Fn pthread_mutexattr_set*
207functions set the attribute that corresponds to each function name.
208.Pp
209The
210.Fn pthread_mutexattr_get*
211functions copy the value of the attribute that corresponds to each function name
212to the location pointed to by the second function parameter.
213.Sh RETURN VALUES
214If successful, these functions return 0.
9385eb3d 215Otherwise, an error number is returned to indicate the error.
5b2abdfb
A
216.Sh ERRORS
217.Fn pthread_mutexattr_init
218will fail if:
219.Bl -tag -width Er
220.It Bq Er ENOMEM
221Out of memory.
222.El
223.Pp
224.Fn pthread_mutexattr_destroy
225will fail if:
226.Bl -tag -width Er
227.It Bq Er EINVAL
228Invalid value for
229.Fa attr .
230.El
231.Pp
232.Fn pthread_mutexattr_setprioceiling
233will fail if:
234.Bl -tag -width Er
235.It Bq Er EINVAL
236Invalid value for
237.Fa attr ,
238or invalid value for
239.Fa prioceiling .
240.El
241.Pp
242.Fn pthread_mutexattr_getprioceiling
243will fail if:
244.Bl -tag -width Er
245.It Bq Er EINVAL
246Invalid value for
247.Fa attr .
248.El
249.Pp
250.Fn pthread_mutexattr_setprotocol
251will fail if:
252.Bl -tag -width Er
253.It Bq Er EINVAL
254Invalid value for
255.Fa attr ,
256or invalid value for
257.Fa protocol .
258.El
259.Pp
260.Fn pthread_mutexattr_getprotocol
261will fail if:
262.Bl -tag -width Er
263.It Bq Er EINVAL
264Invalid value for
265.Fa attr .
266.El
267.Pp
268.Fn pthread_mutexattr_settype
269will fail if:
270.Bl -tag -width Er
271.It Bq Er EINVAL
272Invalid value for
273.Fa attr ,
274or invalid value for
275.Fa type .
276.El
277.Pp
278.Fn pthread_mutexattr_gettype
279will fail if:
280.Bl -tag -width Er
281.It Bq Er EINVAL
282Invalid value for
283.Fa attr .
284.El
285.Sh SEE ALSO
286.Xr pthread_mutex_init 3
287.Sh STANDARDS
288.Fn pthread_mutexattr_init
289and
290.Fn pthread_mutexattr_destroy
291conform to
292.St -p1003.1-96
293.Pp
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 ,
299and
300.Fn pthread_mutexattr_gettype
301conform to
302.St -susv2