forksafe_mutex_trylock()

Updated: April 19, 2023

Attempt to lock a forksafe mutex

Synopsis:

#include <forksafe_mutex.h>

int forksafe_mutex_trylock( forksafe_mutex_t* mutex );

Arguments:

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

Library:

libc, libforksafe_mutex

In QNX Neutrino 7.1 or later, there are two versions of the forksafe_mutex_*() functions:

Description:

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

For more information about forksafe mutexes, see Using fork() in a multithreaded process in the “Processes and Threads” chapter of Getting Started with QNX Neutrino.

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 forksafe_mutex_destroy().
EOWNERDEAD
The mutex is a robust mutex and 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:

QNX Neutrino

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