36.2.6 POSIX Spin Locks

A spinlock is a low overhead lock suitable for use in a realtime thread where it’s known that the thread won’t be paused by the scheduler. Non-realtime threads should use mutexes instead.

Function: int pthread_spin_init (pthread_spinlock_t *lock, int pshared)

Initializes a spinlock. pshared is one of:

PTHREAD_PROCESS_PRIVATE

This spinlock is private to the process which created it.

PTHREAD_PROCESS_SHARED

This spinlock is shared across any process that can access it, for example through shared memory.

This documentation is a stub. For additional information on this function, consult the manual page pthread_spin_init(3) See Linux (The Linux Kernel).

Function: int pthread_spin_destroy (pthread_spinlock_t *lock)

Destroys a spinlock and releases any resources it held. This documentation is a stub. For additional information on this function, consult the manual page pthread_spin_destroy(3) See Linux (The Linux Kernel).

Function: int pthread_spin_lock (pthread_spinlock_t *lock)

Locks a spinlock. Only one thread at a time can lock a spinlock. If another thread has locked this spinlock, the calling thread waits until it is unlocked, then attempts to lock it. This documentation is a stub. For additional information on this function, consult the manual page pthread_spin_lock(3) See Linux (The Linux Kernel).

Function: int pthread_spin_unlock (pthread_spinlock_t *lock)

Unlocks a spinlock. If one or more threads are waiting for the lock to be unlocked, one of them (unspecified which) will succeed in locking it, and will return from pthread_spin_lock). This documentation is a stub. For additional information on this function, consult the manual page pthread_spin_unlock(3) See Linux (The Linux Kernel).

Function: int pthread_spin_trylock (pthread_spinlock_t *lock)

Like pthread_spin_unlock but returns 0 if the lock was unlocked, or EBUSY if it was locked. This documentation is a stub. For additional information on this function, consult the manual page pthread_spin_trylock(3) See Linux (The Linux Kernel).