#include <pthread.h>
int
pthread_mutex_init
(pthread_mutex_t * mutex , pthread_mutexattr_t *
attr );
The pthread_mutex_init function initializes the given mutex with the given attributes. If attr is null, then the default attributes are used.
The pthread_mutex_init function returns zero if the call is successful, otherwise it sets errno to EINVAL and returns -1.
The argument attr must be null. The default attributes are always used.
#include <pthread.h>
int
pthread_mutex_destroy
(pthread_mutex_t *
mutex );
The pthread_mutex_destroy function destroys the given mutex. If the mutex is already destroyed, then errno is set to EINVAL. If the mutex is locked, then errno is set to EBUSY.
The pthread_mutex_destroy function returns zero if the call is successful, otherwise it sets errno and returns -1.
None.
#include <pthread.h>
int
pthread_mutex_lock
(pthread_mutex_t * mutex );
The pthread_mutex_lock function locks the given mutex. If the mutex is already locked, then the calling thread blocks until the thread that currently holds the mutex unlocks it.
The pthread_mutex_lock function returns zero if the call is successful, otherwise it sets errno to EINVAL and returns -1.
None.
#include <pthread.h>
int
pthread_mutex_trylock
(pthread_mutex_t *
mutex );
The pthread_mutex_trylock function tries to lock the given mutex. If the mutex is already locked, the function returns without waiting for the mutex to be unlocked.
The pthread_mutex_trylock function returns zero if the call is successful, otherwise it sets errno to EINVAL and returns -1.
None.
#include <pthread.h>
int
pthread_mutex_unlock
(pthread_mutex_t * mutex );
The pthread_mutex_unlock function unlocks the given mutex.
The pthread_mutex_unlock function returns zero if the call is successful, otherwise it sets errno to EINVAL and returns -1.
None.