OpenBSD manual page server

Manual Page Search Parameters

PTHREAD_MUTEX_LOCK(3) Library Functions Manual PTHREAD_MUTEX_LOCK(3)

pthread_mutex_lock, pthread_mutex_timedlock, pthread_mutex_trylocklock a mutex

#include <pthread.h>

int
pthread_mutex_lock(pthread_mutex_t *mutex);

int
pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *abstime);

int
pthread_mutex_trylock(pthread_mutex_t *mutex);

The () function locks mutex. If the mutex is currently locked by another thread, the calling thread will block until the mutex becomes available.

If the mutex is currently locked by the calling thread, then the behavior depends on the type of the mutex. If mutex is of type PTHREAD_MUTEX_NORMAL, then the calling thread will deadlock and never return from (). If mutex is of type PTHREAD_MUTEX_ERRORCHECK, then EDEADLK is immediately returned. If mutex is of type PTHREAD_MUTEX_RECURSIVE, then the recursion count on the mutex is incremented.

The () function locks mutex like pthread_mutex_lock() except that it will not block or deadlock past the system time specified in abstime. If that time is reached without being able to lock mutex, then it returns ETIMEDOUT.

The () function locks mutex like pthread_mutex_lock() except that if mutex is locked by another thread, or is locked by the calling thread and is not of type PTHREAD_MUTEX_RECURSIVE, then it will immediately return EBUSY.

If successful, pthread_mutex_lock(), pthread_mutex_timedlock(), and pthread_mutex_trylock() will return zero, otherwise an error number will be returned to indicate the error.

pthread_mutex_lock(), pthread_mutex_timedlock(), and pthread_mutex_trylock() will fail if:

[]
The value specified by mutex is invalid.
[]
The mutex is of type PTHREAD_MUTEX_RECURSIVE and the maximum recursion count has been reached.

In addition, pthread_mutex_lock() and pthread_mutex_timedlock() may return the following error:

[]
The mutex is of type PTHREAD_MUTEX_ERRORCHECK and is already locked by the calling thread.

pthread_mutex_timedlock() may return the following error:

[]
The mutex could not be locked and the specified time was reached.

pthread_mutex_trylock() may return the following error:

[]
The mutex could not be locked because it was already locked.

pthread_mutex_destroy(3), pthread_mutex_init(3), pthread_mutex_unlock(3), pthread_mutexattr_settype(3)

pthread_mutex_lock(), pthread_mutex_timedlock(), and pthread_mutex_trylock() conform to IEEE Std 1003.1-2008 (“POSIX.1”).

June 5, 2013 OpenBSD-6.5