United States-English |
|
|
HP-UX Reference > Ppthread_mutex_lock(3T)Pthread LibraryHP-UX 11i Version 3: February 2007 |
|
NAMEpthread_mutex_lock(), pthread_mutex_trylock() — lock or attempt to lock a mutex SYNOPSIS#include <pthread.h> int pthread_mutex_lock( pthread_mutex_t *mutex ); int pthread_mutex_trylock( pthread_mutex_t *mutex ); DESCRIPTIONThe mutex object mutex is locked by calling the pthread_mutex_lock() function. How the calling thread acquires the mutex is dependent upon the type attribute for the mutex. This operation returns with the mutex object referenced by mutex in the locked state with the calling thread as its owner. If the mutex type is PTHREAD_MUTEX_NORMAL, deadlock detection is not provided. Attempting to relock the mutex causes deadlock. If a thread attempts to unlock a mutex that it has not locked or a mutex which is unlocked, undefined behavior results. If the mutex type is PTHREAD_MUTEX_ERRORCHECK, the mutex maintains the concept of an owner. If a thread attempts to relock a mutex that it has already locked, an error shall be returned. If a thread attempts to unlock a mutex that it has not locked or a mutex that is unlocked, an error shall be returned. If the mutex type is PTHREAD_MUTEX_RECURSIVE, then the mutex maintains the concept of an owner and a lock count. When a thread successfully acquires a mutex for the first time, the count field shall be set to one. Every time a thread relocks this mutex, the count field shall be incremented by one. Each time the thread unlocks the mutex, the count field shall be decremented by one. When the count field reaches zero, the mutex shall become available for other threads to acquire. If a thread attempts to unlock a mutex that it has not locked, an error shall be returned. If the mutex type is PTHREAD_MUTEX_NO_OWNER_NP, deadlock detection is not provided. Attempting to relock the mutex causes deadlock. A thread can unlock a mutex that it has not locked. Attempting to unlock an unlocked mutex results in undefined behavior. If the mutex type is PTHREAD_MUTEX_DEFAULT, attempting to recursively lock the mutex results in undefined behavior. Attempting to unlock the mutex if it was not locked by the calling thread results in undefined behavior. Attempting to unlocked the mutex if it is not locked results in undefined behavior. The function pthread_mutex_trylock() is identical to the pthread_mutex_lock() function except that if the mutex object referenced by mutex cannot be acquired after one attempt, the call returns immediately with an error. If a signal is delivered to a thread waiting for a mutex, upon return from the signal handler, the thread shall resume waiting for the mutex as if it was not interrupted. RETURN VALUEUpon successful completion, pthread_mutex_lock() and pthread_mutex_trylock() return zero. Otherwise, an error number is returned to indicate the error (the errno variable is not set). ERRORSIf any of the following occur, the pthread_mutex_lock() and pthread_mutex_trylock() functions return the corresponding error number:
If any of the following occur, the pthread_mutex_trylock() function returns the corresponding error number:
If any of the following occur, the pthread_mutex_lock() and pthread_mutex_trylock() functions return the corresponding error number:
If any of the following occur, the pthread_mutex_lock() function returns the corresponding error number:
WARNINGSA recursive mutex can be locked more than once by the same thread without causing that thread to deadlock. Undefined behavior may result if the owner of a recursive mutex tries to lock the mutex too many times. |
Printable version | ||
|