xref: /freebsd/share/man/man3/pthread_spin_init.3 (revision 2357939bc239bd5334a169b62313806178dd8f30)
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.\" $FreeBSD$
26.\"
27.\" Note: The date here should be updated whenever a non-trivial
28.\" change is made to the manual page.
29.Dd January 22, 2004
30.Dt PTHREAD_SPIN_INIT 3 PTHREAD_SPIN_DESTROY 3
31.Os
32.Sh NAME
33.Nm pthread_spin_init pthread_spin_destroy
34.Nd "initialize or destroy a spin lock"
35.Sh LIBRARY
36.Lb libpthread
37.Lb libthr
38.Sh SYNOPSIS
39.In pthread.h
40.Ft int
41.Fn pthread_spin_init "pthread_spinlock_t *lock" "int pshared"
42.Ft int
43.Fn pthread_spin_destroy "pthread_spinlock_t *lock"
44.Sh DESCRIPTION
45The
46.Fn pthread_spin_init
47function will initialize
48.Fa lock
49to an unlocked state and
50allocate any resources necessary to begin using it.
51If
52.Fa pshared
53is set to
54.Dv PTHREAD_PROCESS_SHARED
55any thread,
56whether belonging to the process in which the spinlock was created or not,
57that has access to the memory area where
58.Fa lock
59resides can use
60.Fa lock .
61If it is set to
62.Dv PTHREAD_PROCESS_PRIVATE
63it can only be used by threads within the same process.
64.Pp
65The
66.Fn pthread_spin_destroy
67function will destroy
68.Fa lock
69and release any resources that may have been allocated on its behalf.
70.Pp
71.Sh DIAGNOSTICS
72If successful,
73both
74.Fn pthread_spin_init
75and
76.Fn pthread_spin_destroy
77will return zero.
78Otherwise an error number will be returned to indicate the error.
79.Pp
80Neither of these functions will return EINTR.
81.Pp
82.Sh ERRORS
83The
84.Fn pthread_spin_init
85and
86.Fn pthread_spin_destroy
87functions will fail if:
88.Bl -tag -width Er
89.It Bq Er EBUSY
90An attempt to initialize or destroy
91.Fa lock
92while it is in use.
93.It Bq Er EINVAL
94The value specified by
95.Fa lock
96is invalid.
97.El
98.Pp
99The
100.Fn pthread_spin_init
101function will fail if:
102.Bl -tag -width Er
103.It Bq Er EAGAIN
104Insufficient resources,
105other than memory,
106to initialize
107.Fa lock .
108.It Bq Er ENOMEM
109Insufficient memory to initialize
110.Fa lock .
111.El
112.Sh SEE ALSO
113.Xr pthread_spin_lock 3 ,
114.Xr pthread_spin_unlock 3
115.Sh HISTORY
116The
117.Fn pthread_spin_init
118and
119.Fn pthread_spin_destroy
120functions first appeared in
121.Lb libpthread
122in
123.Fx 5.2 ,
124and in
125.Lb libthr
126in
127.Fx 5.3 .
128.Sh BUGS
129The implementation of
130.Fn pthread_spin_init
131does not fully conform to
132.St -p1003.2
133because the
134.Fa pshared
135argument is ignored in
136.Lb libthr ,
137and in
138.Lb libpthread
139if any value other than
140.Dv PTHREAD_PROCESSES_PRIVATE
141is specified it returns EINVAL.
142