1.\" Copyright (c) 2004 Michael Telahun Makonnen 2.\" All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23.\" SUCH DAMAGE. 24.\" 25.Dd May 31, 2016 26.Dt PTHREAD_SPIN_INIT 3 27.Os 28.Sh NAME 29.Nm pthread_spin_init , pthread_spin_destroy 30.Nd "initialize or destroy a spin lock" 31.Sh LIBRARY 32.Lb libpthread 33.Sh SYNOPSIS 34.In pthread.h 35.Ft int 36.Fn pthread_spin_init "pthread_spinlock_t *lock" "int pshared" 37.Ft int 38.Fn pthread_spin_destroy "pthread_spinlock_t *lock" 39.Sh DESCRIPTION 40The 41.Fn pthread_spin_init 42function will initialize 43.Fa lock 44to an unlocked state and 45allocate any resources necessary to begin using it. 46If 47.Fa pshared 48is set to 49.Dv PTHREAD_PROCESS_SHARED , 50any thread, 51whether belonging to the process in which the spinlock was created or not, 52that has access to the memory area where 53.Fa lock 54resides, can use 55.Fa lock . 56If it is set to 57.Dv PTHREAD_PROCESS_PRIVATE , 58it can only be used by threads within the same process. 59.Pp 60The 61.Fn pthread_spin_destroy 62function will destroy 63.Fa lock 64and release any resources that may have been allocated on its behalf. 65.Sh RETURN VALUES 66If successful, 67both 68.Fn pthread_spin_init 69and 70.Fn pthread_spin_destroy 71will return zero. 72Otherwise, an error number will be returned to indicate the error. 73.Pp 74Neither of these functions will return 75.Er EINTR . 76.Sh ERRORS 77The 78.Fn pthread_spin_init 79and 80.Fn pthread_spin_destroy 81functions will fail if: 82.Bl -tag -width Er 83.It Bq Er EBUSY 84An attempt to initialize or destroy 85.Fa lock 86while it is in use. 87.It Bq Er EINVAL 88The value specified by 89.Fa lock 90is invalid. 91.El 92.Pp 93The 94.Fn pthread_spin_init 95function will fail if: 96.Bl -tag -width Er 97.It Bq Er EAGAIN 98Insufficient resources, 99other than memory, 100to initialize 101.Fa lock . 102.It Bq Er ENOMEM 103Insufficient memory to initialize 104.Fa lock . 105.El 106.Sh SEE ALSO 107.Xr pthread_spin_lock 3 , 108.Xr pthread_spin_unlock 3 109.Sh HISTORY 110The 111.Fn pthread_spin_init 112and 113.Fn pthread_spin_destroy 114functions first appeared in 115.Lb libkse 116in 117.Fx 5.2 , 118and in 119.Lb libthr 120in 121.Fx 5.3 . 122Support for process-shared spinlocks appeared in 123.Fx 11.0 . 124