pthread_mutex_trylock()

Attempt to lock a mutex

Synopsis:

#include <pthread.h>

int pthread_mutex_trylock( pthread_mutex_t* mutex );

Arguments:

mutex
A pointer to the pthread_mutex_t object that you want to try to lock.

Library:

libc

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

Description:

The pthread_mutex_trylock() function attempts to lock the mutex mutex, but doesn't block the calling thread if the mutex is already locked.

Returns:

EOK
Success.
EAGAIN
The mutex couldn't be acquired because the maximum number of recursive locks for mutex has been exceeded.
EBUSY
The mutex was already locked.
EINVAL
One of the following occurred:
  • The mutex was created with a protocol attribute of PTHREAD_PRIO_PROTECT, and the calling thread's priority is higher than the mutex's current priority ceiling.
  • The mutex is invalid, or it has died (see SyncMutexEvent()).
ENOTRECOVERABLE
The mutex is a robust mutex, and the state that it protects isn't recoverable. All you can do with the mutex is destroy it by calling pthread_mutex_destroy().
EOWNERDEAD
The mutex is a robust mutex and the previous owning thread or the process containing the previous owning thread terminated while holding the mutex lock. The calling thread acquires the mutex lock; it's up to the new owner to make the state consistent (see pthread_mutex_consistent()).

Classification:

POSIX 1003.1

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