Multithreaded Programming Guide

Lock a Mutex

pthread_mutex_lock(3T)

Prototype:
int	pthread_mutex_lock(pthread_mutex_t *mp); 
#include <pthread.h>

pthread_mutex_t mp;
int ret;

ret = pthread_ mutex_lock(&mp); /* acquire the mutex */

Use pthread_mutex_lock() to lock the mutex pointed to by mp. When the mutex is already locked, the calling thread blocks and the mutex waits on a prioritized queue. When pthread_mutex_lock() returns, the mutex is locked and the calling thread is the owner.

Return Values

pthread_mutex_lock() returns zero after completing successfully. Any other returned value indicates that an error occurred. When any of the following conditions occur, the function fails and returns the corresponding value.


EINVAL

The value specified by mp does not refer to an initialized mutex object.


EDEADLK

The current thread already owns the mutex.