pthread_spin_init()

Initialize a thread spinlock

Synopsis:

#include <pthread.h>

int pthread_spin_init( pthread_spinlock_t * spinner,
                       int pshared );

Arguments:

spinner
A pointer to the pthread_spinlock_t object that you want to initialize.
Note: It's always safe, and typically faster, to assure that spinner is 32-bit aligned.
pshared
The value that you want to use for the process-shared attribute of the spinlock. The possible values are:
  • PTHREAD_PROCESS_SHARED — the spinlock may be operated on by any thread that has access to the memory where the spinlock is allocated, even if it's allocated in memory that's shared by multiple processes.
  • PTHREAD_PROCESS_PRIVATE — the spinlock can be operated on only by threads created within the same process as the thread that initialized the spinlock. If threads of differing processes attempt to operate on such a spinlock, the behavior is undefined.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

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.

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.

Returns:

Zero on success, or an error number to indicate the error.

Errors:

EAGAIN
The system doesn't have the resources required to initialize a new spinlock.
EBUSY
The process spinlock, spinner, is in use by another thread and can't be initialized.
EINVAL
Invalid pthread_spinlock_t object spinner.
ENOMEM
The system doesn't have enough free memory to create the new spinlock.

Classification:

POSIX 1003.1

Safety:  
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes