Use the pthread_spin_lock(3C) to lock a spin lock. The calling thread acquires the lock if it is not held by another thread. Otherwise, the thread does not return from the pthread_spin_lock() call until the lock becomes available. The results are undefined if the calling thread holds the lock at the time the call is made.
int pthread_spin_lock(pthread_spinlock_t *lock);
#include <pthread.h> pthread_spinlock_t lock; int ret; ret = pthread_ spin_lock(&lock); /* lock the spinlock */
Upon successful completion, the pthread_spin_lock() function returns 0. Otherwise, one of the following error codes is returned.
The current thread already owns the spin lock.
The value specified by lock does not refer to an initialized spin lock object.