]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/pthread_spin_lock.3
pthread_spin_lock.3: Refer reader to important details in NOTES in pthread_spin_init(3)
[thirdparty/man-pages.git] / man3 / pthread_spin_lock.3
CommitLineData
ce42a8cf
MK
1.\" Copyright (c) 2017, Michael Kerrisk <mtk.manpages@gmail.com>
2.\"
3.\" %%%LICENSE_START(VERBATIM)
4.\" Permission is granted to make and distribute verbatim copies of this
5.\" manual provided the copyright notice and this permission notice are
6.\" preserved on all copies.
7.\"
8.\" Permission is granted to copy and distribute modified versions of this
9.\" manual under the conditions for verbatim copying, provided that the
10.\" entire resulting derived work is distributed under the terms of a
11.\" permission notice identical to this one.
12.\"
13.\" Since the Linux kernel and libraries are constantly changing, this
14.\" manual page may be incorrect or out-of-date. The author(s) assume no
15.\" responsibility for errors or omissions, or for damages resulting from
16.\" the use of the information contained herein. The author(s) may not
17.\" have taken the same level of care in the production of this manual,
18.\" which is licensed free of charge, as they might when working
19.\" professionally.
20.\"
21.\" Formatted or processed versions of this manual, if unaccompanied by
22.\" the source, must acknowledge the copyright and authors of this work.
23.\" %%%LICENSE_END
24.\"
25.TH PTHREAD_SPIN_LOCK 3 2017-09-30 "Linux" "Linux Programmer's Manual"
26.SH NAME
27pthread_spin_lock, pthread_spin_trylock, pthread_spin_unlock \-
28lock and unlock a spin lock
29.SH SYNOPSIS
30.nf
31.B #include <pthread.h>
32.PP
33.BI "int pthread_spin_lock(pthread_spinlock_t *" lock );
34.BI "int pthread_spin_trylock(pthread_spinlock_t *" lock );
35.BI "int pthread_spin_unlock(pthread_spinlock_t *" lock );
36.fi
37.PP
38Compile and link with \fI\-pthread\fP.
39.PP
40.in -4n
41Feature Test Macro Requirements for glibc (see
42.BR feature_test_macros (7)):
43.in
44.PP
45.BR pthread_spin_lock (),
46.BR pthread_spin_trylock ():
47.br
48.RS 4
49.ad l
50_POSIX_C_SOURCE >= 200112L
51.RE
52.ad
53.SH DESCRIPTION
54The
55.BR pthread_spin_lock ()
56function locks the spin lock referred to by
57.IR lock .
58If the spin lock is currently unlocked,
59the calling thread acquires the lock immediately.
60If the spin lock is currently locked by another thread,
61the calling thread spins, testing the lock until it becomes available,
62at which point the calling thread acquires the lock.
63.PP
64Calling
65.BR pthread_spin_lock ()
66on a lock that is already held by the caller results in undefined behavior.
67.PP
68The
69.BR pthread_spin_trylock ()
70function is like
71.BR pthread_spin_lock (),
72except that if the spin lock referred to by
73.I lock
74is currently locked,
75then, instead of spinning, the call returns immediately with the error
76.BR EBUSY .
77.PP
78The
79.BR pthread_spin_unlock ()
80function unlocks the spin lock referred to
81.IR lock .
82If any threads are spinning on the lock,
83one of those threads will then acquire the lock.
84.PP
85Calling
86.BR pthread_spin_unlock ()
87on a lock that is not held by the caller results in undefined behavior.
88.SH RETURN VALUE
89On success, there functions return zero.
90On failure, they return an error number.
91.SH ERRORS
92.BR pthread_spin_lock ()
93may fail with the following errors:
94.TP
95.B EDEADLOCK
96.\" Not detected in glibc
97The system detected a deadlock condition.
98.PP
99.BR pthread_spin_trylock ()
100can fail with the following errors:
101.TP
102.B EBUSY
103The spin lock is currently locked by another thread.
104.SH VERSIONS
105These functions first appeared in glibc in version 2.2.
106.SH CONFORMING TO
107POSIX.1-2001.
108.SH NOTES
109Applying any of the functions described on this page to
110an uninitialized spin lock results in undefined behavior.
f3861c72
MK
111.PP
112Carefully read NOTES in
113.BR pthread_spin_init (3).
ce42a8cf
MK
114.SH SEE ALSO
115.ad l
116.nh
117.\" FIXME . .BR pthread_mutex_lock (3),
118.BR pthread_spin_destroy (3),
119.BR pthread_spin_init (3),
120.BR pthreads (7)