pthread_mutex_lock()

lock a mutex 

Function


SYNOPSIS

#include <pthread.h>

int pthread_mutex_lock(pthread_mutex_t *mutex);


DESCRIPTION

The pthread_mutex_lock() function locks the specified mutex. If the mutex is already locked, the calling thread blocks until the mutex becomes available. This operation returns with the 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 the mutex type is PTHREAD_MUTEX_ERRORCHECK, then error checking is provided. If a thread attempts to relock a mutex that it has already locked, an error is returned.

If the mutex type is PTHREAD_MUTEX_RECURSIVE, the mutex maintains the concept of a lock count. When a thread successfully acquires a mutex for the first time, the lock count is set to one. Every time a thread relocks this mutex, the lock count is incremented by one. The mutex must be unlocked as many time as it was locked for the mutex to be released.

If the mutex type is PTHREAD_MUTEX_DEFAULT, attempting to recursively lock the mutex results in undefined behavior.


PARAMETERS

mutex 

Is the mutex to lock.


RETURN VALUES

On success, pthread_mutex_lock() returns 0. On error, one of the following values is returned:

EINVAL 

mutex is not an initialized mutex.

EFAULT 

mutex is an invalid pointer.

EDEADLK 

The mutex type is PTHREAD_MUTEX_ERRORCHECK and an attempt was made to relock the mutex.


CONFORMANCE

UNIX 98.


MULTITHREAD SAFETY LEVEL

MT-safe.


PORTING ISSUES

None.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
pthread_mutex_init(), pthread_mutex_trylock(), pthread_mutex_unlock(), pthread_mutexattr_settype()


PTC MKS Toolkit 10.4 Documentation Build 39.