]>
Commit | Line | Data |
---|---|---|
2546420a | 1 | .\" $NetBSD: pthread_mutexattr.3,v 1.11 2010/07/08 22:46:34 jruoho Exp $ |
f1a1da6c | 2 | .\" |
2546420a | 3 | .\" Copyright (c) 2002, 2010 The NetBSD Foundation, Inc. |
f1a1da6c A |
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. | |
f1a1da6c A |
13 | .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
14 | .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
15 | .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
16 | .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | |
17 | .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
18 | .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
19 | .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
20 | .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
21 | .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
22 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
23 | .\" POSSIBILITY OF SUCH DAMAGE. | |
24 | .\" | |
25 | .\" Copyright (C) 2000 Jason Evans <jasone@FreeBSD.org>. | |
26 | .\" All rights reserved. | |
27 | .\" | |
28 | .\" Redistribution and use in source and binary forms, with or without | |
29 | .\" modification, are permitted provided that the following conditions | |
30 | .\" are met: | |
31 | .\" 1. Redistributions of source code must retain the above copyright | |
32 | .\" notice(s), this list of conditions and the following disclaimer as | |
33 | .\" the first lines of this file unmodified other than the possible | |
34 | .\" addition of one or more copyright notices. | |
35 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
36 | .\" notice(s), this list of conditions and the following disclaimer in | |
37 | .\" the documentation and/or other materials provided with the | |
38 | .\" distribution. | |
39 | .\" | |
40 | .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY | |
41 | .\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
42 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
43 | .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE | |
44 | .\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
45 | .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
46 | .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR | |
47 | .\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
48 | .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE | |
49 | .\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | |
50 | .\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
51 | .\" | |
2546420a A |
52 | .\" $FreeBSD$ |
53 | .Dd July 9, 2010 | |
f1a1da6c A |
54 | .Dt PTHREAD_MUTEXATTR 3 |
55 | .Os | |
56 | .Sh NAME | |
f1a1da6c | 57 | .Nm pthread_mutexattr_init , |
2546420a | 58 | .Nm pthread_mutexattr_destroy , |
f1a1da6c | 59 | .Nm pthread_mutexattr_setprioceiling , |
2546420a | 60 | .Nm pthread_mutexattr_getprioceiling , |
f1a1da6c | 61 | .Nm pthread_mutexattr_setprotocol , |
2546420a A |
62 | .Nm pthread_mutexattr_getprotocol , |
63 | .Nm pthread_mutexattr_settype , | |
64 | .Nm pthread_mutexattr_gettype | |
f1a1da6c A |
65 | .Nd mutex attribute operations |
66 | .Sh SYNOPSIS | |
2546420a | 67 | .In pthread.h |
f1a1da6c | 68 | .Ft int |
2546420a | 69 | .Fn pthread_mutexattr_init "pthread_mutexattr_t *attr" |
f1a1da6c | 70 | .Ft int |
2546420a | 71 | .Fn pthread_mutexattr_destroy "pthread_mutexattr_t *attr" |
f1a1da6c | 72 | .Ft int |
2546420a | 73 | .Fn pthread_mutexattr_setprioceiling "pthread_mutexattr_t *attr" "int prioceiling" |
f1a1da6c | 74 | .Ft int |
2546420a | 75 | .Fn pthread_mutexattr_getprioceiling "pthread_mutexattr_t *attr" "int *prioceiling" |
f1a1da6c | 76 | .Ft int |
2546420a | 77 | .Fn pthread_mutexattr_setprotocol "pthread_mutexattr_t *attr" "int protocol" |
f1a1da6c | 78 | .Ft int |
2546420a | 79 | .Fn pthread_mutexattr_getprotocol "pthread_mutexattr_t *attr" "int *protocol" |
f1a1da6c | 80 | .Ft int |
2546420a | 81 | .Fn pthread_mutexattr_settype "pthread_mutexattr_t *attr" "int type" |
f1a1da6c | 82 | .Ft int |
2546420a | 83 | .Fn pthread_mutexattr_gettype "pthread_mutexattr_t *attr" "int *type" |
214d78a2 A |
84 | .Ft int |
85 | .Fn pthread_mutexattr_setpolicy_np "pthread_mutexattr_t *attr" "int policy" | |
86 | .Ft int | |
87 | .Fn pthread_mutexattr_getpolicy_np "pthread_mutexattr_t *attr" "int *policy" | |
f1a1da6c A |
88 | .Sh DESCRIPTION |
89 | Mutex attributes are used to specify parameters to | |
90 | .Fn pthread_mutex_init . | |
2546420a A |
91 | Like with thread attributes, |
92 | one attribute object can be used in multiple calls to | |
93 | .Xr pthread_mutex_init 3 , | |
f1a1da6c A |
94 | with or without modifications between calls. |
95 | .Pp | |
96 | The | |
97 | .Fn pthread_mutexattr_init | |
98 | function initializes | |
99 | .Fa attr | |
2546420a | 100 | with all the default mutex attributes. |
f1a1da6c A |
101 | .Pp |
102 | The | |
103 | .Fn pthread_mutexattr_destroy | |
104 | function destroys | |
105 | .Fa attr . | |
106 | .Pp | |
107 | The | |
108 | .Fn pthread_mutexattr_settype | |
2546420a A |
109 | functions set the mutex |
110 | .Fa type | |
111 | value of the attribute. | |
112 | Valid mutex types are: | |
113 | .Bl -tag -width "XXX" -offset 2n | |
114 | .It Dv PTHREAD_MUTEX_NORMAL | |
115 | This type of mutex does not check for usage errors. | |
116 | It will deadlock if reentered, and result in undefined behavior if a | |
117 | locked mutex is unlocked by another thread. | |
118 | Attempts to unlock an already unlocked | |
f1a1da6c A |
119 | .Dv PTHREAD_MUTEX_NORMAL |
120 | mutex will result in undefined behavior. | |
2546420a A |
121 | .It Dv PTHREAD_MUTEX_ERRORCHECK |
122 | These mutexes do check for usage errors. | |
f1a1da6c A |
123 | If an attempt is made to relock a |
124 | .Dv PTHREAD_MUTEX_ERRORCHECK | |
125 | mutex without first dropping the lock, an error will be returned. | |
126 | If a thread attempts to unlock a | |
127 | .Dv PTHREAD_MUTEX_ERRORCHECK | |
2546420a A |
128 | mutex that is locked by another thread, an error will be returned. |
129 | If a thread attempts to unlock a | |
f1a1da6c A |
130 | .Dv PTHREAD_MUTEX_ERRORCHECK |
131 | thread that is unlocked, an error will be returned. | |
2546420a A |
132 | .It Dv PTHREAD_MUTEX_RECURSIVE |
133 | These mutexes allow recursive locking. | |
f1a1da6c A |
134 | An attempt to relock a |
135 | .Dv PTHREAD_MUTEX_RECURSIVE | |
2546420a A |
136 | mutex that is already locked by the same thread succeeds. |
137 | An equivalent number of | |
f1a1da6c | 138 | .Xr pthread_mutex_unlock 3 |
2546420a A |
139 | calls are needed before the mutex will wake another thread waiting |
140 | on this lock. | |
141 | If a thread attempts to unlock a | |
f1a1da6c | 142 | .Dv PTHREAD_MUTEX_RECURSIVE |
2546420a A |
143 | mutex that is locked by another thread, an error will be returned. |
144 | If a thread attempts to unlock a | |
f1a1da6c A |
145 | .Dv PTHREAD_MUTEX_RECURSIVE |
146 | thread that is unlocked, an error will be returned. | |
147 | .Pp | |
2546420a A |
148 | It is advised that |
149 | .Dv PTHREAD_MUTEX_RECURSIVE | |
150 | mutexes are not used with condition variables. | |
151 | This is because of the implicit unlocking done by | |
152 | .Xr pthread_cond_wait 3 | |
153 | and | |
154 | .Xr pthread_cond_timedwait 3 . | |
155 | .It Dv PTHREAD_MUTEX_DEFAULT | |
156 | Also this type of mutex will cause undefined behavior if reentered. | |
f1a1da6c A |
157 | Unlocking a |
158 | .Dv PTHREAD_MUTEX_DEFAULT | |
2546420a A |
159 | mutex locked by another thread will result in undefined behavior. |
160 | Attempts to unlock an already unlocked | |
f1a1da6c A |
161 | .Dv PTHREAD_MUTEX_DEFAULT |
162 | mutex will result in undefined behavior. | |
2546420a A |
163 | This is the default mutex type for |
164 | .Fn pthread_mutexaddr_init . | |
165 | .El | |
f1a1da6c A |
166 | .Pp |
167 | .Fn pthread_mutexattr_gettype | |
168 | functions copy the type value of the attribute to the location pointed to by the second parameter. | |
169 | .Pp | |
170 | The | |
214d78a2 A |
171 | .Fn pthread_mutexattr_setpolicy_np |
172 | function sets the mutex | |
173 | .Fa policy | |
174 | value of the attribute. | |
175 | Valid mutex policies are: | |
176 | .Bl -tag -width "XXX" -offset 2n | |
177 | .It Dv PTHREAD_MUTEX_POLICY_FIRSTFIT_NP | |
178 | The first-fit mutex policy allows acquisition of the mutex to occur in any | |
179 | order. This policy is similar in operation to os_unfair_lock, new contending | |
180 | acquirers may obtain ownership of the mutex ahead of existing waiters. | |
181 | .It Dv PTHREAD_MUTEX_POLICY_FAIRSHARE_NP | |
182 | The fairshare mutex policy guarantees that ownership of a contended mutex will | |
183 | be granted to waiters on a strictly ordered first-in, first-out basis. That is, | |
184 | a mutex holder that unlocks the mutex and then attempts to relock will wait | |
185 | behind existing threads already waiting on the mutex before being granted | |
186 | ownership again. | |
187 | .El | |
188 | .Pp | |
189 | The | |
190 | .Fn pthread_mutexattr_getpolicy_np | |
191 | function copies the mutex | |
192 | .Fa policy | |
193 | value of the attribute to the location pointed to by the second parameter. | |
194 | .Pp | |
195 | The | |
f1a1da6c A |
196 | .Fn pthread_mutexattr_set* |
197 | functions set the attribute that corresponds to each function name. | |
198 | .Pp | |
199 | The | |
200 | .Fn pthread_mutexattr_get* | |
201 | functions copy the value of the attribute that corresponds to each function name | |
202 | to the location pointed to by the second function parameter. | |
203 | .Sh RETURN VALUES | |
204 | If successful, these functions return 0. | |
205 | Otherwise, an error number is returned to indicate the error. | |
214d78a2 A |
206 | .Sh ENVIRONMENT |
207 | The following environment variables change the behavior of the pthread mutex | |
208 | implementation. | |
209 | .Bl -tag -width "XXX" -offset 2n | |
210 | .It Ev PTHREAD_MUTEX_DEFAULT_POLICY | |
211 | Controls the process-wide policy used when initializing a pthread_mutex_t that | |
212 | has not had a policy set via | |
213 | .Fn pthread_mutexattr_setpolicy_np . | |
214 | The valid values are mapped as: | |
215 | .Pp | |
216 | .Bl -tag -width "XXX" | |
217 | .It Fa 1 | |
218 | .Dv PTHREAD_MUTEX_POLICY_FAIRSHARE_NP | |
219 | .It Fa 3 | |
220 | .Dv PTHREAD_MUTEX_POLICY_FIRSTFIT_NP | |
221 | .El | |
222 | .El | |
223 | .Sh BACKWARDS COMPATIBILITY | |
224 | Prior to macOS 10.14 (iOS and tvOS 12.0, watchOS 5.0) the only available | |
225 | pthread mutex policy mode was | |
226 | .Dv PTHREAD_MUTEX_POLICY_FAIRSHARE_NP . | |
227 | macOS 10.14 (iOS and tvOS 12.0, watchOS 5.0) introduces | |
228 | .Dv PTHREAD_MUTEX_POLICY_FIRSTFIT_NP | |
229 | and also makes this the default mode for mutexes initialized without a policy | |
230 | attribute set. | |
231 | .Pp | |
232 | Attempting to use | |
233 | .Fn pthread_mutexattr_setpolicy_np | |
234 | to set the policy of a pthread_mutex_t to | |
235 | .Dv PTHREAD_MUTEX_POLICY_FIRSTFIT_NP | |
236 | on earlier releases will fail with | |
237 | .Er EINVAL | |
238 | and the mutex will continue to operate in fairshare mode. | |
f1a1da6c | 239 | .Sh ERRORS |
2546420a | 240 | The |
f1a1da6c | 241 | .Fn pthread_mutexattr_init |
2546420a | 242 | function shall fail if: |
f1a1da6c A |
243 | .Bl -tag -width Er |
244 | .It Bq Er ENOMEM | |
245 | Out of memory. | |
246 | .El | |
247 | .Pp | |
2546420a | 248 | The |
f1a1da6c | 249 | .Fn pthread_mutexattr_destroy |
2546420a | 250 | function will fail if: |
f1a1da6c A |
251 | .Bl -tag -width Er |
252 | .It Bq Er EINVAL | |
253 | Invalid value for | |
254 | .Fa attr . | |
255 | .El | |
256 | .Pp | |
2546420a | 257 | The |
f1a1da6c | 258 | .Fn pthread_mutexattr_setprioceiling |
2546420a | 259 | function will fail if: |
f1a1da6c A |
260 | .Bl -tag -width Er |
261 | .It Bq Er EINVAL | |
262 | Invalid value for | |
263 | .Fa attr , | |
264 | or invalid value for | |
265 | .Fa prioceiling . | |
266 | .El | |
267 | .Pp | |
2546420a | 268 | The |
f1a1da6c | 269 | .Fn pthread_mutexattr_getprioceiling |
2546420a | 270 | function will fail if: |
f1a1da6c A |
271 | .Bl -tag -width Er |
272 | .It Bq Er EINVAL | |
273 | Invalid value for | |
274 | .Fa attr . | |
275 | .El | |
276 | .Pp | |
2546420a | 277 | The |
f1a1da6c | 278 | .Fn pthread_mutexattr_setprotocol |
2546420a | 279 | function will fail if: |
f1a1da6c A |
280 | .Bl -tag -width Er |
281 | .It Bq Er EINVAL | |
282 | Invalid value for | |
283 | .Fa attr , | |
284 | or invalid value for | |
285 | .Fa protocol . | |
286 | .El | |
287 | .Pp | |
2546420a | 288 | The |
f1a1da6c | 289 | .Fn pthread_mutexattr_getprotocol |
2546420a | 290 | function will fail if: |
f1a1da6c A |
291 | .Bl -tag -width Er |
292 | .It Bq Er EINVAL | |
293 | Invalid value for | |
294 | .Fa attr . | |
295 | .El | |
296 | .Pp | |
2546420a | 297 | The |
f1a1da6c | 298 | .Fn pthread_mutexattr_settype |
2546420a | 299 | function shall fail if: |
f1a1da6c A |
300 | .Bl -tag -width Er |
301 | .It Bq Er EINVAL | |
2546420a A |
302 | The value specified either by |
303 | .Fa type | |
304 | or | |
305 | .Fa attr | |
306 | is invalid. | |
f1a1da6c A |
307 | .El |
308 | .Pp | |
2546420a | 309 | The |
f1a1da6c | 310 | .Fn pthread_mutexattr_gettype |
2546420a | 311 | function will fail if: |
f1a1da6c A |
312 | .Bl -tag -width Er |
313 | .It Bq Er EINVAL | |
314 | Invalid value for | |
315 | .Fa attr . | |
316 | .El | |
214d78a2 A |
317 | .Pp |
318 | The | |
319 | .Fn pthread_mutexattr_setpolicy_np | |
320 | function will fail if: | |
321 | .Bl -tag -width Er | |
322 | .It Bq Er EINVAL | |
323 | Invalid value for | |
324 | .Fa attr . | |
325 | .El | |
326 | .Pp | |
327 | The | |
328 | .Fn pthread_mutexattr_getpolicy_np | |
329 | function will fail if: | |
330 | .Bl -tag -width Er | |
331 | .It Bq Er EINVAL | |
332 | The value specified either by | |
333 | .Fa type | |
334 | or | |
335 | .Fa attr | |
336 | is invalid. | |
337 | .El | |
f1a1da6c A |
338 | .Sh SEE ALSO |
339 | .Xr pthread_mutex_init 3 | |
340 | .Sh STANDARDS | |
2546420a | 341 | The |
f1a1da6c A |
342 | .Fn pthread_mutexattr_init |
343 | and | |
344 | .Fn pthread_mutexattr_destroy | |
2546420a | 345 | functions conform to |
f1a1da6c A |
346 | .St -p1003.1-96 |
347 | .Pp | |
2546420a | 348 | The |
f1a1da6c A |
349 | .Fn pthread_mutexattr_setprioceiling , |
350 | .Fn pthread_mutexattr_getprioceiling , | |
351 | .Fn pthread_mutexattr_setprotocol , | |
352 | .Fn pthread_mutexattr_getprotocol , | |
353 | .Fn pthread_mutexattr_settype , | |
354 | and | |
355 | .Fn pthread_mutexattr_gettype | |
2546420a | 356 | functions conform to |
f1a1da6c | 357 | .St -susv2 |