PTHREAD_SPIN_INIT(3)

NAME
pthread_spin_init - initialize a spin lock

LIBRARY
libpthread

SYNOPSIS
#include <pthread.h>
int
pthread_spin_init(pthread_spinlock_t *lock, int pshared);

DESCRIPTION
The pthread_spin_init() function is used to initialize a spinlock. The pshared parameter is currently unused and all spinlocks exhibit the PTHREAD_PROCESS_SHARED property.

The results of calling pthread_spin_init() with an already initialized lock are undefined.

RETURN VALUES
If successful, the pthread_spin_init() function will return zero. Otherwise an error number will be returned to indicate the error.

ERRORS
The pthread_spin_init() function shall fail if:

[ENOMEM]
    Insufficient memory exists to initialize the lock.

The pthread_spin_init() function may fail if:

[EINVAL]
    The lock parameter was NULL or the pshared parameter was neither PTHREAD_PROCESS_SHARED nor PTHREAD_PROCESS_PRIVATE.

SEE ALSO
pthread_spin_destroy(3), pthread_spin_lock(3), pthread_spin_trylock(3), pthread_spin_unlock(3)

STANDARDS
pthread_spin_init() conforms to p1003.1-2001.

CAVEATS
Applications using spinlocks are vulnerable to the effects of priority inversion. Applications using real-time threads (SCHED_FIFO, SCHED_RR) should not use these interfaces. Outside carefully controlled environments, priority inversion with spinlocks can lead to system deadlock. Mutexes are preferable in nearly every possible use case.