1 .\" Copyright (C) 2000 Jason Evans <jasone@FreeBSD.org>.
2 .\" Copyright (c) 2021 The FreeBSD Foundation, Inc.
3 .\" All rights reserved.
5 .\" Part of this documentation was written by
6 .\" Konstantin Belousov <kib@FreeBSD.org> under sponsorship
7 .\" from the FreeBSD Foundation.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice(s), this list of conditions and the following disclaimer as
14 .\" the first lines of this file unmodified other than the possible
15 .\" addition of one or more copyright notices.
16 .\" 2. Redistributions in binary form must reproduce the above copyright
17 .\" notice(s), this list of conditions and the following disclaimer in
18 .\" the documentation and/or other materials provided with the
21 .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
22 .\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
25 .\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28 .\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
30 .\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31 .\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 .Dt PTHREAD_MUTEXATTR 3
36 .Nm pthread_mutexattr_init ,
37 .Nm pthread_mutexattr_destroy ,
38 .Nm pthread_mutexattr_setprioceiling ,
39 .Nm pthread_mutexattr_getprioceiling ,
40 .Nm pthread_mutexattr_setprotocol ,
41 .Nm pthread_mutexattr_getprotocol ,
42 .Nm pthread_mutexattr_setpshared ,
43 .Nm pthread_mutexattr_getpshared ,
44 .Nm pthread_mutexattr_setrobust ,
45 .Nm pthread_mutexattr_getrobust ,
46 .Nm pthread_mutexattr_settype ,
47 .Nm pthread_mutexattr_gettype
48 .Nd mutex attribute operations
54 .Fn pthread_mutexattr_init "pthread_mutexattr_t *attr"
56 .Fn pthread_mutexattr_destroy "pthread_mutexattr_t *attr"
58 .Fo pthread_mutexattr_setprioceiling
59 .Fa "pthread_mutexattr_t *attr" "int prioceiling"
62 .Fo pthread_mutexattr_getprioceiling
63 .Fa "const pthread_mutexattr_t *attr" "int *prioceiling"
66 .Fn pthread_mutexattr_setprotocol "pthread_mutexattr_t *attr" "int protocol"
68 .Fo pthread_mutexattr_getprotocol
69 .Fa "const pthread_mutexattr_t *restrict attr" "int *restrict protocol"
72 .Fo pthread_mutexattr_setpshared
73 .Fa "pthread_mutexattr_t *attr" "int shared"
76 .Fo pthread_mutexattr_getpshared
77 .Fa "const pthread_mutexattr_t *attr" "int *shared"
80 .Fn pthread_mutexattr_setrobust "pthread_mutexattr_t *attr" "int robust"
82 .Fn pthread_mutexattr_getrobust "pthread_mutexattr_t *attr" "int *robust"
84 .Fn pthread_mutexattr_settype "pthread_mutexattr_t *attr" "int type"
86 .Fo pthread_mutexattr_gettype
87 .Fa "const pthread_mutexattr_t *restrict attr" "int *restrict type"
90 Mutex attributes are used to specify parameters to
91 .Fn pthread_mutex_init .
92 One attribute object can be used in multiple calls to
93 .Fn pthread_mutex_init ,
94 with or without modifications between calls.
97 .Fn pthread_mutexattr_init
100 with all the default mutex attributes.
103 .Fn pthread_mutexattr_destroy
108 .Fn pthread_mutexattr_setprioceiling
109 function sets the priority ceiling for the mutex, used
110 by threads executed under the
111 .Dv PTHREAD_PRIO_PROTECT
115 .Fn pthread_mutexattr_setprotocol
116 function specifies the protocol to be followed in utilizing mutexes.
119 argument can take one of the following values:
120 .Bl -tag -width PTHREAD_PRIO_PROTECT
121 .It PTHREAD_PRIO_NONE
122 Priority and scheduling of the thread owning this mutex is not
123 affected by its mutex ownership.
124 .It PTHREAD_PRIO_INHERIT
125 Request priority-inheritance protocol, where the thread owning the mutex
126 is executed at the highest priority among priorities of all threads waiting
127 on any mutex owned by this thread.
128 .It PTHREAD_PRIO_PROTECT
129 Request priority-inheritance protocol, where the thread owning the mutex
130 is executed at highest priority among priorities or priority ceilings of
131 all threads waiting on any mutex owned by this thread.
135 .Fn pthread_mutexattr_setpshared
136 function sets the process-shared attribute of
138 to the value specified in
142 may have one of the following values:
143 .Bl -tag -width ".Dv PTHREAD_PROCESS_PRIVATE"
144 .It Dv PTHREAD_PROCESS_PRIVATE
145 The mutex may only be used by threads in the same process as the one
146 that created the object.
147 .It Dv PTHREAD_PROCESS_SHARED
148 The mutex may be used by
149 threads in processes other than the one that created the object,
150 assuming other processes share access to the memory where the mutex
155 for details of the implementation of the shared mutexes,
156 and their limitations.
159 .Fn pthread_mutexattr_setrobust
160 function specifies robustness attribute of the mutex.
161 Possible values for the
164 .Bl -tag -width PTHREAD_MUTEX_STALLED
165 .It PTHREAD_MUTEX_STALLED
166 No special actions are taken if the thread owning the mutex is terminated
167 without unlocking the mutex lock.
168 This can lead to deadlocks if no other thread can unlock the mutex.
169 This is the default value.
170 .It PTHREAD_MUTEX_ROBUST
171 If the process containing the owning thread of a robust mutex, or owning
172 thread, terminates while holding the mutex lock, the next thread that
173 acquires the mutex is notified about the termination
176 from the locking function.
178 .Xr pthread_mutex_consistent 3
179 can be used to repair the mutex lock state, or
180 .Xr pthread_mutex_unlock 3
181 can unlock the mutex lock but also put it an unusable state,
182 where all further attempts to acquire it result in the
188 .Fn pthread_mutexattr_settype
189 function sets the type of the mutex.
190 The type affects the behavior of calls which lock and unlock the mutex.
191 The possible values for the
194 .Bl -tag -width PTHREAD_MUTEX_ERRORCHECK
195 .It PTHREAD_MUTEX_NORMAL
196 Both recursive locking, and unlocking when the lock is not owned by the current
197 thread, cause an error to be returned from the corresponding functions.
199 .Dv PTHREAD_MUTEX_ERRORCHECK
200 but somewhat contradicts the behavior mandated by POSIX.
201 .It PTHREAD_MUTEX_ERRORCHECK
202 Both recursive locking, and unlocking when the lock is not owned by the current
203 thread, cause an error returned from the corresponding functions.
204 .It PTHREAD_MUTEX_RECURSIVE
205 Recursive locking is allowed.
206 Attempt to unlock when current thread is not an owner of the lock causes
207 an error to be returned.
208 .It PTHREAD_MUTEX_DEFAULT
211 implementation maps this type to
212 .Dv PTHREAD_MUTEX_ERRORCHECK
217 .Fn pthread_mutexattr_get*
218 functions copy the value of the attribute that corresponds to each function name
219 to the location pointed to by the second function parameter.
221 If successful, these functions return 0.
222 Otherwise, an error number is returned to indicate the error.
225 .Fn pthread_mutexattr_init
226 function will fail if:
233 .Fn pthread_mutexattr_destroy
234 function will fail if:
242 .Fn pthread_mutexattr_setprioceiling
243 function will fail if:
253 .Fn pthread_mutexattr_getprioceiling
254 function will fail if:
262 .Fn pthread_mutexattr_setprotocol
263 function will fail if:
273 .Fn pthread_mutexattr_getprotocol
274 function will fail if:
282 .Fn pthread_mutexattr_setpshared
283 function will fail if:
293 .Fn pthread_mutexattr_getpshared
294 function will fail if:
302 .Fn pthread_mutexattr_settype
303 function will fail if:
313 .Fn pthread_mutexattr_gettype
314 function will fail if:
322 .Fn pthread_mutexattr_setrobust
323 function will fail if:
333 .Fn pthread_mutexattr_getrobust
334 function will fail if:
342 .Xr pthread_mutex_init 3
345 .Fn pthread_mutexattr_init
347 .Fn pthread_mutexattr_destroy
352 .Fn pthread_mutexattr_setprioceiling ,
353 .Fn pthread_mutexattr_getprioceiling ,
354 .Fn pthread_mutexattr_setprotocol ,
355 .Fn pthread_mutexattr_getprotocol ,
356 .Fn pthread_mutexattr_setpshared ,
357 .Fn pthread_mutexattr_getpshared ,
358 .Fn pthread_mutexattr_settype ,
360 .Fn pthread_mutexattr_gettype
364 .Fn pthread_mutexattr_setrobust
366 .Fn pthread_mutexattr_getrobust