pthread_spin_trylock3
Lock or unlock a spin lock
Part of pthread_spin_lock(3).
Usage
int
int
int
Library
POSIX Threads Library (libpthread, -lpthread)
Overview
The pthread_spin_lock() function will acquire lock if it is not currently owned by another thread. If the lock cannot be acquired immediately, it will spin attempting to acquire the lock (it will not sleep) until it becomes available.
The pthread_spin_trylock() function is the same as pthread_spin_lock() except that if it cannot acquire lock immediately it will return with an error.
The pthread_spin_unlock() function will release lock, which must have been previously locked by a call to pthread_spin_lock() or pthread_spin_trylock().
Return values
If successful, all these functions will return zero. Otherwise, an error number will be returned to indicate the error.
None of these functions will return EINTR.
Errors
The pthread_spin_lock(), pthread_spin_trylock() and pthread_spin_unlock() functions will fail if:
- [EINVAL]
-
The value specified by lock is invalid or is not initialized.
The pthread_spin_lock() function may fail if:
- [EDEADLK]
-
The calling thread already owns the lock.
The pthread_spin_trylock() function will fail if:
- [EBUSY]
-
Another thread currently holds lock.
The pthread_spin_unlock() function may fail if:
- [EPERM]
-
The calling thread does not own lock.
History
- FreeBSD 16.0-CURRENT (2026-10-27) to FreeBSD 13.3-RELEASE: the text shown here
- FreeBSD 13.2-RELEASE to FreeBSD 13.0-RELEASE
- FreeBSD 12.4-RELEASE
- FreeBSD 12.3-RELEASE
- FreeBSD 12.2-RELEASE
- FreeBSD 12.1-RELEASE
- FreeBSD 12.0-RELEASE
- FreeBSD 11.4-RELEASE
- FreeBSD 11.3-RELEASE
- FreeBSD 11.2-RELEASE
- FreeBSD 11.1-RELEASE
- FreeBSD 11.0-RELEASE
- FreeBSD 10.4-RELEASE
- FreeBSD 10.3-RELEASE
- FreeBSD 10.2-RELEASE
- FreeBSD 10.1-RELEASE
- FreeBSD 10.0-RELEASE
- FreeBSD 9.3-RELEASE
- FreeBSD 9.2-RELEASE
- FreeBSD 9.1-RELEASE
- FreeBSD 9.0-RELEASE
- FreeBSD 8.4-RELEASE
- FreeBSD 8.3-RELEASE
- FreeBSD 8.2-RELEASE
- FreeBSD 8.1-RELEASE
- FreeBSD 8.0-RELEASE
- FreeBSD 7.4-RELEASE
- FreeBSD 7.3-RELEASE
- FreeBSD 7.2-RELEASE
- FreeBSD 7.1-RELEASE
- FreeBSD 7.0-RELEASE
- FreeBSD 6.4-RELEASE
- FreeBSD 6.3-RELEASE to FreeBSD 5.3-RELEASE