vuoi
o PayPal
tutte le volte che vuoi
pthread_mutex_lock
pthread_mutex_lock is a function that is used to acquire a mutex in a multi-threaded program. The mutex is a synchronization object that is used to protect shared resources from concurrent access by multiple threads.
When a thread calls pthread_mutex_lock, it will block until it can acquire the mutex. If the mutex is already locked by another thread, the calling thread will be put to sleep until the mutex becomes available.
In the case of PTHREAD_MUTEX_RECURSIVE mutexes, a thread can acquire the mutex multiple times. Each call to pthread_mutex_lock must be matched with a call to pthread_mutex_unlock in order to release the mutex. The mutex becomes available when the count reaches zero and the calling thread no longer has any locks on this mutex.
If a signal is delivered to a thread waiting for a mutex, upon return from the signal handler the thread resumes waiting for the mutex as if it was not interrupted.
The pthread_mutex_lock() and pthread_mutex_unlock() functions return zero if successful. Otherwise, an error number is returned to indicate the error.
The function pthread_mutex_trylock() returns zero if a lock on the mutex object referenced by mutex is acquired. Otherwise, an error number is returned to indicate the error.
The pthread_mutex_lock() and pthread_mutex_trylock() functions will fail if the mutex was created with the protocol attribute having the value PTHREAD_PRIO_PROTECT and the calling thread's...
priority is higher than the mutex's current priority ceiling.
The pthread_mutex_trylock()
function will fail if:
- [EBUSY] The mutex could not be acquired because it was already locked.
The pthread_mutex_lock()
, pthread_mutex_trylock()
, and pthread_mutex_unlock()
functions may fail if:
- [EINVAL] The value specified by mutex does not refer to an initialised mutex object.
- [EAGAIN] The mutex could not be acquired because the maximum number of recursive locks for mutex has been exceeded.
The pthread_mutex_lock()
function may fail if:
- [EDEADLK] The current thread already owns the mutex.
The pthread_mutex_unlock()
function may fail if:
- [EPERM] The current thread does not own the mutex.
These functions will not return an error code of [EINTR].
EXAMPLES
None.
APPLICATION USAGE
2 di 3 10/06/2010 16:27