pthread_spin_lock or pthread_spin_trylock Subroutine

Purpose

Locks a spin lock object.

Syntax

#include <pthread.h>

int pthread_spin_lock(pthread_spinlock_t *lock); 
int pthread_spin_trylock(pthread_spinlock_t *lock);

Description

The pthread_spin_lock subroutine locks the spin lock referenced by the lock parameter. The calling thread shall acquire the lock if it is not held by another thread. Otherwise, the thread spins (that is, 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. The pthread_spin_trylock subroutine locks the spin lock referenced by the lock parameter if it is not held by any thread. Otherwise, the function fails.

The results are undefined if any of these subroutines is called with an uninitialized spin lock.

Return Values

Upon successful completion, these functions return zero; otherwise, an error number is returned to indicate the error.

Error Codes

Item Description
EINVAL The value specified by the lock parameter does not refer to an initialized spin lock object.
The pthread_spin_lock subroutine fails if:
Item Description
EDEADLK The calling thread already holds the lock.
The pthread_spin_trylock subroutine fails if:
Item Description
EBUSY A thread currently holds the lock.