Open System Services System Calls Reference Manual (G06.29+, H06.08+, J06.03+)
pthread_mutex_trylock(2) OSS System Calls Reference Manual
NAME
pthread_mutex_trylock - Attempts to lock a specified mutex but does not wait if the mutex is
already locked
LIBRARY
G-series native OSS processes: /G/system/sysnn/zsptsrl
32-bit H-series and J-series OSS processes that use the POSIX User Thread Model library:
/G/system/zdllnnn/zputdll
64-bit H-series and J-series OSS processes that use the POSIX User Thread Model library:
/G/system/zdllnnn/yputdll
H-series and J-series OSS processes that use the Standard POSIX Threads library:
/G/system/zdllnnn/zsptdll
SYNOPSIS
#include <pthread.h> | #include <spthread.h>
/* pthread.h is required to use POSIX User Thread Model library */
/* spthread.h is required to use Standard POSIX Threads library */
int pthread_mutex_trylock(
pthread_mutex_t *mutex);
PARAMETERS
mutex Specifies the mutex to be locked.
DESCRIPTION
This function attempts to lock the mutex specified by the mutex parameter. When a thread calls
this function, an attempt is made to immediately lock the mutex. If the mutex is successfully
locked, this function returns 0 (zero) and the calling thread becomes the mutex’s current owner.
If the specified mutex is already locked, the calling thread does not wait for the mutex to become
available and the function returns.
This function does the following:
• If mutex is a fast or nonrecursive mutex: if the mutex is already locked by any thread
(including the calling thread) when this function is called, this function returns [EBUSY]
and the calling thread does not wait to acquire the lock.
• If mutex is a recursive mutex: if the mutex is either unlocked or owned by the calling
thread, this function returns 0 (zero) and the mutex lock count is incremented. (To
unlock a recursive mutex, each lock must be matched by a call to the
pthread_mutex_unlock() function.)
On systems running H06.21 or later H-series RVUs or J06.10 or later J-series RVUs, you can use
either the POSIX User Thread Model library or the Standard POSIX Threads library for threaded
applications.
To use this function in a threaded application that uses the POSIX User Thread Model library on
systems running H06.21 or later RVUs or J06.10 or later RVUs, you must perform all of the fol-
lowing tasks:
• Include the pthread.h header file in the application.
• Compile the application using the _PUT_MODEL_ feature test macro or equivalent
compiler command option.
• Link the application to the zputdll library (/G/system/zdllnnn/zputdll).
On systems running H06.24 or later H-series RVUs or J06.13 or later J-series RVUs, you can use
the POSIX User Thread Model library with 32-bit or 64-bit threaded applications.
5−158 Hewlett-Packard Company 527186-023