1PTHREAD_SPIN_LOCK(3)       Linux Programmer's Manual      PTHREAD_SPIN_LOCK(3)
2
3
4

NAME

6       pthread_spin_lock, pthread_spin_trylock, pthread_spin_unlock - lock and
7       unlock a spin lock
8

SYNOPSIS

10       #include <pthread.h>
11
12       int pthread_spin_lock(pthread_spinlock_t *lock);
13       int pthread_spin_trylock(pthread_spinlock_t *lock);
14       int pthread_spin_unlock(pthread_spinlock_t *lock);
15
16       Compile and link with -pthread.
17
18   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
19
20       pthread_spin_lock(), pthread_spin_trylock():
21           _POSIX_C_SOURCE >= 200112L
22

DESCRIPTION

24       The pthread_spin_lock() function locks the spin  lock  referred  to  by
25       lock.   If  the  spin  lock  is  currently unlocked, the calling thread
26       acquires the lock immediately.  If the spin lock is currently locked by
27       another  thread,  the  calling  thread spins, testing the lock until it
28       becomes available, at which point the calling thread acquires the lock.
29
30       Calling pthread_spin_lock() on a lock that is already held by the call‐
31       er  or  a  lock that has not been initialized with pthread_spin_init(3)
32       results in undefined behavior.
33
34       The pthread_spin_trylock() function is like pthread_spin_lock(), except
35       that  if  the  spin lock referred to by lock is currently locked, then,
36       instead of spinning, the call returns immediately with the error EBUSY.
37
38       The pthread_spin_unlock() function unlocks the spin  lock  referred  to
39       lock.   If  any  threads are spinning on the lock, one of those threads
40       will then acquire the lock.
41
42       Calling pthread_spin_unlock() on a lock that is not held by the  caller
43       results in undefined behavior.
44

RETURN VALUE

46       On  success,  these  functions return zero.  On failure, they return an
47       error number.
48

ERRORS

50       pthread_spin_lock() may fail with the following errors:
51
52       EDEADLOCK
53              The system detected a deadlock condition.
54
55       pthread_spin_trylock() fails with the following errors:
56
57       EBUSY  The spin lock is currently locked by another thread.
58

VERSIONS

60       These functions first appeared in glibc in version 2.2.
61

CONFORMING TO

63       POSIX.1-2001.
64

NOTES

66       Applying any of the functions described on this page to  an  uninitial‐
67       ized spin lock results in undefined behavior.
68
69       Carefully read NOTES in pthread_spin_init(3).
70

SEE ALSO

72       pthread_spin_destroy(3), pthread_spin_init(3), pthreads(7)
73

COLOPHON

75       This page is part of release 5.04 of the Linux man-pages project.  A
76       description of the project, information about reporting bugs, and the
77       latest version of this page, can be found at
78       https://www.kernel.org/doc/man-pages/.
79
80
81
82Linux                             2017-09-30              PTHREAD_SPIN_LOCK(3)
Impressum