Adelsbach Enhanced Threading Library

Manual Pages (DD-00013-001)

Enhanced Threading Library > mtx_trylock (3)
HTML TXT PDF PS
mtx_trylock(3) Library Functions Manual mtx_trylock(3)

mtx_trylockattempt to acquire a mutex

library “threads”
#include <threads.h>

int
mtx_trylock(mtx_t *mtx);

The function () will attempt to acquire a mutex mtx if it has not been acquired already by an other thread.

If the mutex is already held by the current thread and locking recursion was specified in mtx_init(3) an additional instance of the mutex will be acquired in the current thread. In this case to unlock the mutex mtx_unlock(3) must be called an equal number of times as (), mtx_lock(3) or mtx_timedlock(3) have been called from the same thread on the same mutex, in order to unlock the mutex for other threads.

Upon success mtx_trylock() will return thrd_success if the mutex has been acquired or thrd_busy if the mutex is being held by an other thread. In case of error thrd_error will be returned.

mtx_init(3) mtx_destroy(3) mtx_unlock(3) mtx_lock(3) mtx_timedlock(3)

The mtx_trylock() function first appeared in the C11 standard ISO/IEC 9899:2011.

Jan Adelsbach <jan@jadelsbach.de>

May 9, 2020 Debian