![]() |
![]() |
![]() |
Initialize a thread spinlock
#include <pthread.h> int pthread_spin_init( pthread_spinlock_t * spinner, int pshared );
libc
The pthread_spin_init() function allocates the resources required for the thread spinlock spinner, and initializes spinner to an unlocked state.
Any thread that can access the memory where spinner is allocated can operate on the spinlock. If the Thread Process-Shared Synchronization option is supported and the value of pshared is PTHREAD_PROCESS_SHARED, the spin lock may be operated on by any thread that has access to the memory were the spin lock is allocated, even if it's allocated in memory that's shared by multiple processes. If the value is PTHREAD_PROCESS_PRIVATE, the spin lock can only be operated on by threads created within the same process as the thread that initialized the spin lock. If threads of differing processes attempt to operate on such a spin lock, the behaviour is undefined.
Results are undefined if you call pthread_spin_init() on a spinner that's already initialized, or if you try to use a spinlock that hasn't been initialized.
Zero on success, or an error number to indicate the error.
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |
pthread_spin_destroy(), pthread_spin_lock(), pthread_spin_trylock(), pthread_spin_unlock()
![]() |
![]() |
![]() |