PTHREAD_SPIN_INIT(3) | Library Functions Manual | PTHREAD_SPIN_INIT(3)

# NAME

`pthread_spin_init`, `pthread_spin_destroy` — initialize and destroy a spinlock object

# SYNOPSIS

POSIX Threads Library (libpthread, -lpthread)
`#include <pthread.h>`

int
`pthread_spin_init`(pthread_spinlock_t *lock, int pshared);

int
`pthread_spin_destroy`(pthread_spinlock_t *lock);

# DESCRIPTION

The `pthread_spin_init`() function creates a new spinlock object, with sharing attributes specified by pshared.

The `pthread_spin_destroy`() function frees the resources allocated for the lock.

# RETURN VALUES

If successful, `pthread_spin_init`() and `pthread_spin_destroy`() return zero; otherwise an error number is returned to indicate the error.

# ERRORS

`pthread_spin_init`() will fail if:

[`EINVAL`]
  The value specified by lock is invalid.
[`ENOMEM`]
  The process cannot allocate enough memory to create another spinlock object.
[`ENOTSUP`]
  The shared attributes specified by pshared are not supported by the current implementation.

`pthread_spin_destroy`() will fail if:

[`EINVAL`]
  The value specified by lock is invalid.
[`EBUSY`]
  The lock is still in use.

# SEE ALSO

pthread_spin_lock(3), pthread_spin_unlock(3)

# STANDARDS

`pthread_spin_init`() and `pthread_spin_destroy`() conform to IEEE Std 1003.1-2008 (“POSIX.1”).

# BUGS

Currently only `PTHREAD_PROCESS_PRIVATE` spinlocks are supported and the pshared attribute is always set that way. Any attempts to initialize it to a different value will trigger `ENOTSUP`.

June 7, 2025 | Debian