You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
serhij.zolotukhin edited this page Dec 7, 2025
·
1 revision
Spinlock
- is a mutual exclusion device that can have only two values: "locked" and "unlocked."
- is a lock which causes a thread trying to acquire it to simply wait in a loop ("spin")
while repeatedly checking if the lock is available.
Since the thread remains active but is not performing a useful task,
the use of such a lock is a kind of busy waiting.
spin — вращение
Read/Write Spin Locks
These locks allow any number of readers into a critical section simultaneously,
but writers must have exclusive access.
API Pthread
#include <pthread.h>
int pthread_spin_lock(pthread_spinlock_t *lock);
int pthread_spin_trylock(pthread_spinlock_t *lock);
API
<linux/spinlock.h>
// Once you call spin_lock, you will spin until the lock becomes available.
void spin_lock(spinlock_t *lock);
// To release a lock that you have obtained, pass it to:
void spin_unlock(spinlock_t *lock);