Open System Services System Calls Reference Manual (G06.25+, H06.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
H-series OSS processes: /G/system/zdllnnn/zsptdll
SYNOPSIS
#include <spthread.h>
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.)
RETURN VALUES
If an error condition occurs, this function returns an integer value indicating the type of error.
Possible return values are:
0 Successful completion.
[EBUSY] The mutex is already locked; therefore, it was not acquired.
[EINVAL] The value specified by the mutex parameter is not a valid mutex.
[ENOMEM] There is insufficient memory to lock a statically initialized mutex.
RELATED INFORMATION
Functions: pthread_mutex_destroy(2), pthread_mutex_init(2), pthread_mutex_lock(2),
pthread_mutex_unlock(2).
STANDARDS CONFORMANCE
This function and recursive mutexes are an extension to the XPG4 Version 2 specification. Inter-
faces documented on this reference page conform to the following industry standards:
• IEEE Std 1003.1c-1995, POSIX System Application Program Interface
The use of the header file spthread.h is an HP exception to the POSIX standard. The return of
[ENOMEM] is an HP extension to the POSIX standard.
5−80 Hewlett-Packard Company 527186-003