1*cada2c18Snjoly.\" $NetBSD: pthread_mutexattr.3,v 1.14 2017/02/02 10:48:22 njoly Exp $ 255818196Snathanw.\" 38fe295c5Sjruoho.\" Copyright (c) 2002, 2010 The NetBSD Foundation, Inc. 455818196Snathanw.\" All rights reserved. 555818196Snathanw.\" Redistribution and use in source and binary forms, with or without 655818196Snathanw.\" modification, are permitted provided that the following conditions 755818196Snathanw.\" are met: 855818196Snathanw.\" 1. Redistributions of source code must retain the above copyright 955818196Snathanw.\" notice, this list of conditions and the following disclaimer. 1055818196Snathanw.\" 2. Redistributions in binary form must reproduce the above copyright 1155818196Snathanw.\" notice, this list of conditions and the following disclaimer in the 1255818196Snathanw.\" documentation and/or other materials provided with the distribution. 1355818196Snathanw.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 1455818196Snathanw.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 1555818196Snathanw.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1655818196Snathanw.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 1755818196Snathanw.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 1855818196Snathanw.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 1955818196Snathanw.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2055818196Snathanw.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2155818196Snathanw.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2255818196Snathanw.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2355818196Snathanw.\" POSSIBILITY OF SUCH DAMAGE. 2455818196Snathanw.\" 2555818196Snathanw.\" Copyright (C) 2000 Jason Evans <jasone@FreeBSD.org>. 2655818196Snathanw.\" All rights reserved. 2755818196Snathanw.\" 2855818196Snathanw.\" Redistribution and use in source and binary forms, with or without 2955818196Snathanw.\" modification, are permitted provided that the following conditions 3055818196Snathanw.\" are met: 3155818196Snathanw.\" 1. Redistributions of source code must retain the above copyright 3255818196Snathanw.\" notice(s), this list of conditions and the following disclaimer as 3355818196Snathanw.\" the first lines of this file unmodified other than the possible 3455818196Snathanw.\" addition of one or more copyright notices. 3555818196Snathanw.\" 2. Redistributions in binary form must reproduce the above copyright 3655818196Snathanw.\" notice(s), this list of conditions and the following disclaimer in 3755818196Snathanw.\" the documentation and/or other materials provided with the 3855818196Snathanw.\" distribution. 3955818196Snathanw.\" 4055818196Snathanw.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY 4155818196Snathanw.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 4255818196Snathanw.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 4355818196Snathanw.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE 4455818196Snathanw.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 4555818196Snathanw.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 4655818196Snathanw.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 4755818196Snathanw.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 4855818196Snathanw.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 4955818196Snathanw.\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 5055818196Snathanw.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 5155818196Snathanw.\" 5255818196Snathanw.\" $FreeBSD: src/lib/libpthread/man/pthread_mutexattr.3,v 1.8 2002/09/16 19:29:29 mini Exp $ 537cf7644fSchristos.Dd June 12, 2016 5455818196Snathanw.Dt PTHREAD_MUTEXATTR 3 5555818196Snathanw.Os 5655818196Snathanw.Sh NAME 5755818196Snathanw.Nm pthread_mutexattr_init , 5855818196Snathanw.Nm pthread_mutexattr_destroy , 597cf7644fSchristos.Nm pthread_mutexattr_setprioceiling , 607cf7644fSchristos.Nm pthread_mutexattr_getprioceiling , 617cf7644fSchristos.Nm pthread_mutexattr_setprotocol , 627cf7644fSchristos.Nm pthread_mutexattr_getprotocol , 6355818196Snathanw.Nm pthread_mutexattr_settype , 647cf7644fSchristos.Nm pthread_mutexattr_gettype , 657cf7644fSchristos.Nm pthread_mutexattr_getpshared , 667cf7644fSchristos.Nm pthread_mutexattr_setpshared 6755818196Snathanw.Nd mutex attribute operations 6855818196Snathanw.Sh LIBRARY 6955818196Snathanw.Lb libpthread 7055818196Snathanw.Sh SYNOPSIS 7155818196Snathanw.In pthread.h 7255818196Snathanw.Ft int 7355818196Snathanw.Fn pthread_mutexattr_init "pthread_mutexattr_t *attr" 7455818196Snathanw.Ft int 7555818196Snathanw.Fn pthread_mutexattr_destroy "pthread_mutexattr_t *attr" 767cf7644fSchristos.Ft int 777cf7644fSchristos.Fn pthread_mutexattr_setprioceiling \ 787cf7644fSchristos"pthread_mutexattr_t *attr" "int prioceiling" 797cf7644fSchristos.Ft int 807cf7644fSchristos.Fn pthread_mutexattr_getprioceiling \ 817cf7644fSchristos"pthread_mutexattr_t *attr" "int *prioceiling" 827cf7644fSchristos.Ft int 837cf7644fSchristos.Fn pthread_mutexattr_setprotocol \ 847cf7644fSchristos"pthread_mutexattr_t *attr" "int protocol" 857cf7644fSchristos.Ft int 867cf7644fSchristos.Fn pthread_mutexattr_getprotocol \ 877cf7644fSchristos"pthread_mutexattr_t *attr" "int *protocol" 8855818196Snathanw.Ft int 8955818196Snathanw.Fn pthread_mutexattr_settype "pthread_mutexattr_t *attr" "int type" 9055818196Snathanw.Ft int 918fe295c5Sjruoho.Fn pthread_mutexattr_gettype \ 928fe295c5Sjruoho"pthread_mutexattr_t * restrict attr" "int * restrict type" 937cf7644fSchristos.Ft int 947cf7644fSchristos.Fn pthread_mutexattr_getpshared \ 957cf7644fSchristos"const pthread_mutexattr_t * __restrict attr" "int * __restrict pshared" 967cf7644fSchristos.Ft int 977cf7644fSchristos.Fn pthread_mutexattr_setpshared \ 987cf7644fSchristos"pthread_mutexattr_t * attr" "int pshared" 9955818196Snathanw.Sh DESCRIPTION 10055818196SnathanwMutex attributes are used to specify parameters to 10155818196Snathanw.Fn pthread_mutex_init . 1028fe295c5SjruohoLike with thread attributes, 1038fe295c5Sjruohoone attribute object can be used in multiple calls to 1048fe295c5Sjruoho.Xr pthread_mutex_init 3 , 10555818196Snathanwwith or without modifications between calls. 10655818196Snathanw.Pp 10755818196SnathanwThe 10855818196Snathanw.Fn pthread_mutexattr_init 10955818196Snathanwfunction initializes 11055818196Snathanw.Fa attr 11155818196Snathanwwith all the default mutex attributes. 11255818196Snathanw.Pp 11355818196SnathanwThe 11455818196Snathanw.Fn pthread_mutexattr_destroy 11555818196Snathanwfunction destroys 11655818196Snathanw.Fa attr . 11755818196Snathanw.Pp 11855818196SnathanwThe 11955818196Snathanw.Fn pthread_mutexattr_settype 120ebe1a1a4Sjruohofunctions set the mutex 121ebe1a1a4Sjruoho.Fa type 122ebe1a1a4Sjruohovalue of the attribute. 12352e496a6SwizValid mutex types are: 124ebe1a1a4Sjruoho.Bl -tag -width "XXX" -offset 2n 125ebe1a1a4Sjruoho.It Dv PTHREAD_MUTEX_NORMAL 126ebe1a1a4SjruohoThis type of mutex does not check for usage errors. 127ebe1a1a4SjruohoIt will deadlock if reentered, and result in undefined behavior if a 12852e496a6Swizlocked mutex is unlocked by another thread. 12952e496a6SwizAttempts to unlock an already unlocked 13055818196Snathanw.Dv PTHREAD_MUTEX_NORMAL 13155818196Snathanwmutex will result in undefined behavior. 132ebe1a1a4Sjruoho.It Dv PTHREAD_MUTEX_ERRORCHECK 133ebe1a1a4SjruohoThese mutexes do check for usage errors. 13455818196SnathanwIf an attempt is made to relock a 13555818196Snathanw.Dv PTHREAD_MUTEX_ERRORCHECK 136ebe1a1a4Sjruohomutex without first dropping the lock, an error will be returned. 13752e496a6SwizIf a thread attempts to unlock a 13855818196Snathanw.Dv PTHREAD_MUTEX_ERRORCHECK 13952e496a6Swizmutex that is locked by another thread, an error will be returned. 14052e496a6SwizIf a thread attempts to unlock a 14155818196Snathanw.Dv PTHREAD_MUTEX_ERRORCHECK 142ebe1a1a4Sjruohothread that is unlocked, an error will be returned. 143ebe1a1a4Sjruoho.It Dv PTHREAD_MUTEX_RECURSIVE 144ebe1a1a4SjruohoThese mutexes allow recursive locking. 14555818196SnathanwAn attempt to relock a 14655818196Snathanw.Dv PTHREAD_MUTEX_RECURSIVE 14752e496a6Swizmutex that is already locked by the same thread succeeds. 14852e496a6SwizAn equivalent number of 14955818196Snathanw.Xr pthread_mutex_unlock 3 15052e496a6Swizcalls are needed before the mutex will wake another thread waiting 15152e496a6Swizon this lock. 15252e496a6SwizIf a thread attempts to unlock a 15355818196Snathanw.Dv PTHREAD_MUTEX_RECURSIVE 15452e496a6Swizmutex that is locked by another thread, an error will be returned. 15552e496a6SwizIf a thread attempts to unlock a 15655818196Snathanw.Dv PTHREAD_MUTEX_RECURSIVE 15755818196Snathanwthread that is unlocked, an error will be returned. 15855818196Snathanw.Pp 159ebe1a1a4SjruohoIt is advised that 160ebe1a1a4Sjruoho.Dv PTHREAD_MUTEX_RECURSIVE 161ebe1a1a4Sjruohomutexes are not used with condition variables. 162ebe1a1a4SjruohoThis is because of the implicit unlocking done by 163ebe1a1a4Sjruoho.Xr pthread_cond_wait 3 164ebe1a1a4Sjruohoand 165ebe1a1a4Sjruoho.Xr pthread_cond_timedwait 3 . 166ebe1a1a4Sjruoho.It Dv PTHREAD_MUTEX_DEFAULT 167ebe1a1a4SjruohoAlso this type of mutex will cause undefined behavior if reentered. 16855818196SnathanwUnlocking a 16955818196Snathanw.Dv PTHREAD_MUTEX_DEFAULT 17052e496a6Swizmutex locked by another thread will result in undefined behavior. 17152e496a6SwizAttempts to unlock an already unlocked 17255818196Snathanw.Dv PTHREAD_MUTEX_DEFAULT 17355818196Snathanwmutex will result in undefined behavior. 17455818196Snathanw.Pp 175ebe1a1a4SjruohoThis is the default mutex type for 176*cada2c18Snjoly.Fn pthread_mutexattr_init . 177ebe1a1a4Sjruoho.El 178ebe1a1a4Sjruoho.Pp 179ebe1a1a4SjruohoThe 18055818196Snathanw.Fn pthread_mutexattr_gettype 18152e496a6Swizfunctions copy the type value of the attribute to the location 18252e496a6Swizpointed to by the second parameter. 1837cf7644fSchristos.Pp 1847cf7644fSchristosThe 1857cf7644fSchristos.Fn pthread_mutexattr_getpshared 1867cf7644fSchristosfunction obtains the value of the process-shared attribute from 1877cf7644fSchristosthe attributes object referenced by 1887cf7644fSchristos.Fa attr . 1897cf7644fSchristos.Pp 1907cf7644fSchristosThe 1917cf7644fSchristos.Fn pthread_mutexattr_setpshared 1927cf7644fSchristosfunction is used to set the process-shared attribute in an initialised 1937cf7644fSchristosattributes object referenced by 1947cf7644fSchristos.Fa attr . 1957cf7644fSchristos.Pp 1967cf7644fSchristosThe 1977cf7644fSchristos.Fn pthread_mutexattr_getprotocol 1987cf7644fSchristosand 1997cf7644fSchristos.Fn pthread_mutexattr_setprotocol 2007cf7644fSchristosfunctions shall get and set the protocol attribute of a mutex attributes 2017cf7644fSchristosobject pointed to by 2027cf7644fSchristos.Fa attr 2037cf7644fSchristoswhich was previously created by the function 2047cf7644fSchristos.Fn pthread_mutexattr_init . 2057cf7644fSchristos.Pp 2067cf7644fSchristosThe 2077cf7644fSchristos.Fn pthread_mutexattr_getprioceiling 2087cf7644fSchristosand 2097cf7644fSchristos.Fn pthread_mutexattr_setprioceiling 2107cf7644fSchristosfunctions, shall get and set the priority ceiling attribute of a mutex attributes 2117cf7644fSchristosobject pointed to by 2127cf7644fSchristos.Fa attr 2137cf7644fSchristoswhich was previously created by the function 2147cf7644fSchristos.Fn pthread_mutexattr_init . 21555818196Snathanw.Sh RETURN VALUES 21655818196SnathanwIf successful, these functions return 0. 21755818196SnathanwOtherwise, an error number is returned to indicate the error. 21855818196Snathanw.Sh ERRORS 2198fe295c5SjruohoThe 22055818196Snathanw.Fn pthread_mutexattr_init 2218fe295c5Sjruohofunction shall fail if: 22255818196Snathanw.Bl -tag -width Er 22355818196Snathanw.It Bq Er ENOMEM 224568accb2SpeterInsufficient memory exists to initialize the mutex attributes object. 22555818196Snathanw.El 22655818196Snathanw.Pp 2278fe295c5SjruohoThe 22855818196Snathanw.Fn pthread_mutexattr_settype 2298fe295c5Sjruohofunction shall fail if: 23055818196Snathanw.Bl -tag -width Er 23155818196Snathanw.It Bq Er EINVAL 2328fe295c5SjruohoThe value specified either by 23355818196Snathanw.Fa type 2348fe295c5Sjruohoor 2358fe295c5Sjruoho.Fa attr 23655818196Snathanwis invalid. 23755818196Snathanw.El 2388fe295c5Sjruoho.Pp 2398fe295c5SjruohoNo error numbers are defined for the 2408fe295c5Sjruoho.Fn pthread_mutexattr_destroy 2418fe295c5Sjruohoand 2428fe295c5Sjruoho.Fn pthread_mutexattr_gettype 2438fe295c5Sjruohofunctions. 2447cf7644fSchristos.Pp 2457cf7644fSchristos.Fn pthread_mutexattr_setprioceiling 2467cf7644fSchristosmay fail if: 2477cf7644fSchristos.Bl -tag -width Er 2487cf7644fSchristos.It Bq Er EINVAL 2497cf7644fSchristosInvalid value for 2507cf7644fSchristos.Fa attr , 2517cf7644fSchristosor invalid value for 2527cf7644fSchristos.Fa prioceiling . 2537cf7644fSchristos.El 2547cf7644fSchristos.Pp 2557cf7644fSchristos.Fn pthread_mutexattr_getprioceiling 2567cf7644fSchristosmay fail if: 2577cf7644fSchristos.Bl -tag -width Er 2587cf7644fSchristos.It Bq Er EINVAL 2597cf7644fSchristosInvalid value for 2607cf7644fSchristos.Fa attr . 2617cf7644fSchristos.El 2627cf7644fSchristos.Pp 2637cf7644fSchristos.Fn pthread_mutexattr_setprotocol 2647cf7644fSchristosmay fail if: 2657cf7644fSchristos.Bl -tag -width Er 2667cf7644fSchristos.It Bq Er EINVAL 2677cf7644fSchristosInvalid value for 2687cf7644fSchristos.Fa attr , 2697cf7644fSchristosor invalid value for 2707cf7644fSchristos.Fa protocol . 2717cf7644fSchristos.El 2727cf7644fSchristos.Pp 2737cf7644fSchristos.Fn pthread_mutexattr_getprotocol 2747cf7644fSchristosmay fail if: 2757cf7644fSchristos.Bl -tag -width Er 2767cf7644fSchristos.It Bq Er EINVAL 2777cf7644fSchristosInvalid value for 2787cf7644fSchristos.Fa attr . 2797cf7644fSchristos.El 2807cf7644fSchristos.Pp 2817cf7644fSchristos.Fn pthread_mutexattr_getpshared 2827cf7644fSchristosand 2837cf7644fSchristos.Fn pthread_mutexattr_setpshared 2847cf7644fSchristosmay fail if: 2857cf7644fSchristos.Bl -tag -width Er 2867cf7644fSchristos.It Bq Er EINVAL 2877cf7644fSchristosthe value specified by 2887cf7644fSchristos.Fa attr 2897cf7644fSchristosis invalid. 290b9737c74Swiz.El 29155818196Snathanw.Sh SEE ALSO 29255818196Snathanw.Xr pthread_mutex_init 3 29355818196Snathanw.Sh STANDARDS 2948fe295c5SjruohoThese functions conform to 2958fe295c5Sjruoho.St -p1003.1-2001 . 2967cf7644fSchristos.Sh BUGS 2977cf7644fSchristosThe 2987cf7644fSchristos.Fn pthread_mutexattr_getpshared 2997cf7644fSchristosand 3007cf7644fSchristos.Fn pthread_mutexattr_setpshared 3017cf7644fSchristosfunctions are hidden by default since only thread shared attributes 3027cf7644fSchristosare supported. 303