1.\" $NetBSD: pthread_mutexattr.3,v 1.7 2007/04/17 21:11:47 heinz 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.\" 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.\" 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 57.Dt PTHREAD_MUTEXATTR 3 58.Os 59.Sh NAME 60.Nm pthread_mutexattr_init , 61.Nm pthread_mutexattr_destroy , 62.\" .Nm pthread_mutexattr_setprioceiling , 63.\" .Nm pthread_mutexattr_getprioceiling , 64.\" .Nm pthread_mutexattr_setprotocol , 65.\" .Nm pthread_mutexattr_getprotocol , 66.Nm pthread_mutexattr_settype , 67.Nm pthread_mutexattr_gettype 68.Nd mutex attribute operations 69.Sh LIBRARY 70.Lb libpthread 71.Sh SYNOPSIS 72.In pthread.h 73.Ft int 74.Fn pthread_mutexattr_init "pthread_mutexattr_t *attr" 75.Ft int 76.Fn pthread_mutexattr_destroy "pthread_mutexattr_t *attr" 77.\" .Ft int 78.\" .Fn pthread_mutexattr_setprioceiling "pthread_mutexattr_t *attr" "int prioceiling" 79.\" .Ft int 80.\" .Fn pthread_mutexattr_getprioceiling "pthread_mutexattr_t *attr" "int *prioceiling" 81.\" .Ft int 82.\" .Fn pthread_mutexattr_setprotocol "pthread_mutexattr_t *attr" "int protocol" 83.\" .Ft int 84.\" .Fn pthread_mutexattr_getprotocol "pthread_mutexattr_t *attr" "int *protocol" 85.Ft int 86.Fn pthread_mutexattr_settype "pthread_mutexattr_t *attr" "int type" 87.Ft int 88.Fn pthread_mutexattr_gettype "pthread_mutexattr_t * restrict attr" "int * restrict type" 89.Sh DESCRIPTION 90Mutex attributes are used to specify parameters to 91.Fn pthread_mutex_init . 92One attribute object can be used in multiple calls to 93.Fn pthread_mutex_init , 94with or without modifications between calls. 95.Pp 96The 97.Fn pthread_mutexattr_init 98function initializes 99.Fa attr 100with all the default mutex attributes. 101.Pp 102The 103.Fn pthread_mutexattr_destroy 104function destroys 105.Fa attr . 106.Pp 107The 108.Fn pthread_mutexattr_settype 109functions set the mutex type value of the attribute. 110Valid mutex types are: 111.Dv PTHREAD_MUTEX_NORMAL , 112.Dv PTHREAD_MUTEX_ERRORCHECK , 113.Dv PTHREAD_MUTEX_RECURSIVE , 114and 115.Dv PTHREAD_MUTEX_DEFAULT . 116The default mutex type for 117.Fn pthread_mutexaddr_init 118is 119.Dv PTHREAD_MUTEX_DEFAULT . 120.Pp 121.Dv PTHREAD_MUTEX_NORMAL 122mutexes do not check for usage errors. 123.Dv PTHREAD_MUTEX_NORMAL 124mutexes will deadlock if reentered, and result in undefined behavior if a 125locked mutex is unlocked by another thread. 126Attempts to unlock an already unlocked 127.Dv PTHREAD_MUTEX_NORMAL 128mutex will result in undefined behavior. 129.Pp 130.Dv PTHREAD_MUTEX_ERRORCHECK 131mutexes do check for usage errors. 132If an attempt is made to relock a 133.Dv PTHREAD_MUTEX_ERRORCHECK 134mutex without first dropping the lock an error will be returned. 135If a thread attempts to unlock a 136.Dv PTHREAD_MUTEX_ERRORCHECK 137mutex that is locked by another thread, an error will be returned. 138If a thread attempts to unlock a 139.Dv PTHREAD_MUTEX_ERRORCHECK 140thread that is unlocked, an error will be 141returned. 142.Pp 143.Dv PTHREAD_MUTEX_RECURSIVE 144mutexes allow recursive locking. 145An attempt to relock a 146.Dv PTHREAD_MUTEX_RECURSIVE 147mutex that is already locked by the same thread succeeds. 148An equivalent number of 149.Xr pthread_mutex_unlock 3 150calls are needed before the mutex will wake another thread waiting 151on this lock. 152If a thread attempts to unlock a 153.Dv PTHREAD_MUTEX_RECURSIVE 154mutex that is locked by another thread, an error will be returned. 155If a thread attempts to unlock a 156.Dv PTHREAD_MUTEX_RECURSIVE 157thread that is unlocked, an error will be returned. 158.Pp 159.Dv PTHREAD_MUTEX_DEFAULT 160mutexes result in undefined behavior if reentered. 161Unlocking a 162.Dv PTHREAD_MUTEX_DEFAULT 163mutex locked by another thread will result in undefined behavior. 164Attempts to unlock an already unlocked 165.Dv PTHREAD_MUTEX_DEFAULT 166mutex will result in undefined behavior. 167.Pp 168.Fn pthread_mutexattr_gettype 169functions copy the type value of the attribute to the location 170pointed to by the second parameter. 171.Sh RETURN VALUES 172If successful, these functions return 0. 173Otherwise, an error number is returned to indicate the error. 174.Sh ERRORS 175.Fn pthread_mutexattr_init 176shall fail if: 177.Bl -tag -width Er 178.It Bq Er ENOMEM 179Insufficient memory exists to initialize the mutex attributes object. 180.El 181.Pp 182.Fn pthread_mutexattr_settype 183shall fail if: 184.Bl -tag -width Er 185.It Bq Er EINVAL 186The value specified by 187.Fa type 188is invalid. 189.El 190.Pp 191.\" .Fn pthread_mutexattr_setprioceiling 192.\" may fail if: 193.\" .Bl -tag -width Er 194.\" .It Bq Er EINVAL 195.\" Invalid value for 196.\" .Fa attr , 197.\" or invalid value for 198.\" .Fa prioceiling . 199.\" .El 200.\" .Pp 201.\" .Fn pthread_mutexattr_getprioceiling 202.\" may fail if: 203.\" .Bl -tag -width Er 204.\" .It Bq Er EINVAL 205.\" Invalid value for 206.\" .Fa attr . 207.\" .El 208.\" .Pp 209.\" .Fn pthread_mutexattr_setprotocol 210.\" may fail if: 211.\" .Bl -tag -width Er 212.\" .It Bq Er EINVAL 213.\" Invalid value for 214.\" .Fa attr , 215.\" or invalid value for 216.\" .Fa protocol . 217.\" .El 218.\" .Pp 219.\" .Fn pthread_mutexattr_getprotocol 220.\" may fail if: 221.\" .Bl -tag -width Er 222.\" .It Bq Er EINVAL 223.\" Invalid value for 224.\" .Fa attr . 225.\" .El 226.\" .Pp 227.Pp 228.Fn pthread_mutexattr_destroy , 229.Fn pthread_mutexattr_settype , 230and 231.Fn pthread_mutexattr_gettype 232may fail if: 233.Bl -tag -width Er 234.It Bq Er EINVAL 235Invalid value for 236.Fa attr . 237.El 238.Sh SEE ALSO 239.Xr pthread_mutex_init 3 240.Sh STANDARDS 241.Fn pthread_mutexattr_init , 242.Fn pthread_mutexattr_destroy , 243.Fn pthread_mutexattr_settype , 244.\" .Fn pthread_mutexattr_setprioceiling , 245.\" .Fn pthread_mutexattr_getprioceiling , 246.\" .Fn pthread_mutexattr_setprotocol , 247.\" .Fn pthread_mutexattr_getprotocol , 248and 249.Fn pthread_mutexattr_gettype 250conform to 251.St -p1003.1-96 . 252