1 .\" Copyright (c) 2017, Michael Kerrisk <mtk.manpages@gmail.com>
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.
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.
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
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .TH PTHREAD_SPIN_LOCK 3 2021-03-22 "Linux" "Linux Programmer's Manual"
27 pthread_spin_lock, pthread_spin_trylock, pthread_spin_unlock \-
28 lock and unlock a spin lock
31 .B #include <pthread.h>
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 );
38 Compile and link with \fI\-pthread\fP.
41 Feature Test Macro Requirements for glibc (see
42 .BR feature_test_macros (7)):
45 .BR pthread_spin_lock (),
46 .BR pthread_spin_trylock ():
48 _POSIX_C_SOURCE >= 200112L
52 .BR pthread_spin_lock ()
53 function locks the spin lock referred to by
55 If the spin lock is currently unlocked,
56 the calling thread acquires the lock immediately.
57 If the spin lock is currently locked by another thread,
58 the calling thread spins, testing the lock until it becomes available,
59 at which point the calling thread acquires the lock.
62 .BR pthread_spin_lock ()
63 on a lock that is already held by the caller
64 or a lock that has not been initialized with
65 .BR pthread_spin_init (3)
66 results in undefined behavior.
69 .BR pthread_spin_trylock ()
71 .BR pthread_spin_lock (),
72 except that if the spin lock referred to by
75 then, instead of spinning, the call returns immediately with the error
79 .BR pthread_spin_unlock ()
80 function unlocks the spin lock referred to
82 If any threads are spinning on the lock,
83 one of those threads will then acquire the lock.
86 .BR pthread_spin_unlock ()
87 on a lock that is not held by the caller results in undefined behavior.
89 On success, these functions return zero.
90 On failure, they return an error number.
92 .BR pthread_spin_lock ()
93 may fail with the following errors:
96 .\" Not detected in glibc
97 The system detected a deadlock condition.
99 .BR pthread_spin_trylock ()
100 fails with the following errors:
103 The spin lock is currently locked by another thread.
105 These functions first appeared in glibc in version 2.2.
109 Applying any of the functions described on this page to
110 an uninitialized spin lock results in undefined behavior.
112 Carefully read NOTES in
113 .BR pthread_spin_init (3).
117 .\" FIXME . .BR pthread_mutex_lock (3),
118 .BR pthread_spin_destroy (3),
119 .BR pthread_spin_init (3),