pthread_mutex_unlock()

unlock a mutex 

Function


SYNOPSIS

#include <pthread.h>

int pthread_mutex_unlock(pthread_mutex_t *mutex);


DESCRIPTION

The pthread_mutex_unlock() function attempts to unlock the specified mutex. If there are threads blocked on the mutex object when pthread_mutex_unlock() is called, resulting in the mutex becoming available, the scheduling policy is used to determine which thread acquires the mutex.

If the mutex type is PTHREAD_MUTEX_NORMAL, error detection is not provided. If a thread attempts to unlock a mutex that is has not locked or a mutex which is unlocked, undefined behavior results.

If the mutex type is PTHREAD_MUTEX_ERRORCHECK, error checking is provided. If a thread attempts to unlock a mutex that it has not locked or a mutex that is unlocked, 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. When the lock count reaches zero, the mutex becomes available for other threads to acquire. If a thread attempts to unlock a mutex that it has not locked or a mutex that is unlocked, an error is returned.

If the mutex type is PTHREAD_MUTEX_DEFAULT, attempting to unlock the mutex if it was not locked by the calling thread results in undefined behavior. Attempting to unlock the mutex if it is not locked results in undefined behavior.


PARAMETERS

mutex 

Is the mutex to unlock.


RETURN VALUES

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

EINVAL 

mutex is not an initialized mutex.

EFAULT 

mutex is an invalid pointer.

EPERM 

The calling thread does not own 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_lock(), pthread_mutex_trylock(), pthread_mutexattr_settype()


PTC MKS Toolkit 10.4 Documentation Build 39.