Multithreaded Programming Guide

Unlock a Mutex

pthread_mutex_unlock(3T)

Use pthread_mutex_unlock() to unlock the mutex pointed to by mp.

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

pthread_mutex_t mp;
int ret;

ret = pthread_ mutex_unlock(&mp); /* release the mutex */

The mutex must be locked and the calling thread must be the one that last locked the mutex (the owner). When any other threads are waiting for the mutex to become available, the thread at the head of the queue is unblocked.

Return Values

pthread_mutex_unlock() 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.