]>
Commit | Line | Data |
---|---|---|
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 | |
27 | pthread_spin_lock, pthread_spin_trylock, pthread_spin_unlock \- | |
28 | lock 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 | |
38 | Compile and link with \fI\-pthread\fP. | |
39 | .PP | |
40 | .in -4n | |
41 | Feature 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 | |
54 | The | |
55 | .BR pthread_spin_lock () | |
56 | function locks the spin lock referred to by | |
57 | .IR lock . | |
58 | If the spin lock is currently unlocked, | |
59 | the calling thread acquires the lock immediately. | |
60 | If the spin lock is currently locked by another thread, | |
61 | the calling thread spins, testing the lock until it becomes available, | |
62 | at which point the calling thread acquires the lock. | |
63 | .PP | |
64 | Calling | |
65 | .BR pthread_spin_lock () | |
07fa47a5 MK |
66 | on a lock that is already held by the caller |
67 | or a lock that has not been initialized with | |
68 | .BR pthread_spin_init (3) | |
69 | results in undefined behavior. | |
ce42a8cf MK |
70 | .PP |
71 | The | |
72 | .BR pthread_spin_trylock () | |
73 | function is like | |
74 | .BR pthread_spin_lock (), | |
75 | except that if the spin lock referred to by | |
76 | .I lock | |
77 | is currently locked, | |
78 | then, instead of spinning, the call returns immediately with the error | |
79 | .BR EBUSY . | |
80 | .PP | |
81 | The | |
82 | .BR pthread_spin_unlock () | |
83 | function unlocks the spin lock referred to | |
84 | .IR lock . | |
85 | If any threads are spinning on the lock, | |
86 | one of those threads will then acquire the lock. | |
87 | .PP | |
88 | Calling | |
89 | .BR pthread_spin_unlock () | |
90 | on a lock that is not held by the caller results in undefined behavior. | |
91 | .SH RETURN VALUE | |
af79528e | 92 | On success, these functions return zero. |
ce42a8cf MK |
93 | On failure, they return an error number. |
94 | .SH ERRORS | |
95 | .BR pthread_spin_lock () | |
96 | may fail with the following errors: | |
97 | .TP | |
98 | .B EDEADLOCK | |
99 | .\" Not detected in glibc | |
100 | The system detected a deadlock condition. | |
101 | .PP | |
102 | .BR pthread_spin_trylock () | |
26cd31fd | 103 | fails with the following errors: |
ce42a8cf MK |
104 | .TP |
105 | .B EBUSY | |
106 | The spin lock is currently locked by another thread. | |
107 | .SH VERSIONS | |
108 | These functions first appeared in glibc in version 2.2. | |
109 | .SH CONFORMING TO | |
110 | POSIX.1-2001. | |
111 | .SH NOTES | |
112 | Applying any of the functions described on this page to | |
113 | an uninitialized spin lock results in undefined behavior. | |
f3861c72 MK |
114 | .PP |
115 | Carefully read NOTES in | |
116 | .BR pthread_spin_init (3). | |
ce42a8cf MK |
117 | .SH SEE ALSO |
118 | .ad l | |
119 | .nh | |
120 | .\" FIXME . .BR pthread_mutex_lock (3), | |
121 | .BR pthread_spin_destroy (3), | |
122 | .BR pthread_spin_init (3), | |
123 | .BR pthreads (7) |