1pthread_spin_lock(3) Library Functions Manual pthread_spin_lock(3)
2
3
4
6 pthread_spin_lock, pthread_spin_trylock, pthread_spin_unlock - lock and
7 unlock a spin lock
8
10 POSIX threads library (libpthread, -lpthread)
11
13 #include <pthread.h>
14
15 int pthread_spin_lock(pthread_spinlock_t *lock);
16 int pthread_spin_trylock(pthread_spinlock_t *lock);
17 int pthread_spin_unlock(pthread_spinlock_t *lock);
18
19 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
20
21 pthread_spin_lock(), pthread_spin_trylock():
22 _POSIX_C_SOURCE >= 200112L
23
25 The pthread_spin_lock() function locks the spin lock referred to by
26 lock. If the spin lock is currently unlocked, the calling thread ac‐
27 quires the lock immediately. If the spin lock is currently locked by
28 another thread, the calling thread spins, testing the lock until it be‐
29 comes available, at which point the calling thread acquires the lock.
30
31 Calling pthread_spin_lock() on a lock that is already held by the
32 caller or a lock that has not been initialized with
33 pthread_spin_init(3) results in undefined behavior.
34
35 The pthread_spin_trylock() function is like pthread_spin_lock(), except
36 that if the spin lock referred to by lock is currently locked, then,
37 instead of spinning, the call returns immediately with the error EBUSY.
38
39 The pthread_spin_unlock() function unlocks the spin lock referred to
40 lock. If any threads are spinning on the lock, one of those threads
41 will then acquire the lock.
42
43 Calling pthread_spin_unlock() on a lock that is not held by the caller
44 results in undefined behavior.
45
47 On success, these functions return zero. On failure, they return an
48 error number.
49
51 pthread_spin_lock() may fail with the following errors:
52
53 EDEADLOCK
54 The system detected a deadlock condition.
55
56 pthread_spin_trylock() fails with the following errors:
57
58 EBUSY The spin lock is currently locked by another thread.
59
61 POSIX.1-2008.
62
64 glibc 2.2. POSIX.1-2001.
65
67 Applying any of the functions described on this page to an uninitial‐
68 ized spin lock results in undefined behavior.
69
70 Carefully read NOTES in pthread_spin_init(3).
71
73 pthread_spin_destroy(3), pthread_spin_init(3), pthreads(7)
74
75
76
77Linux man-pages 6.04 2023-03-30 pthread_spin_lock(3)