14.7. Pthread Mutex Functions

14.7.1. The pthread_mutex_init function

Synopsis
#include <pthread.h>

int pthread_mutex_init (pthread_mutex_t * mutex , pthread_mutexattr_t * attr );

Description

The pthread_mutex_init function initializes the given mutex with the given attributes. If attr is null, then the default attributes are used.

Returns

The pthread_mutex_init function returns zero if the call is successful, otherwise it sets errno to EINVAL and returns -1.

Implementation Notes

The argument attr must be null. The default attributes are always used.

14.7.2. The pthread_mutex_destroy function

Synopsis
#include <pthread.h>

int pthread_mutex_destroy (pthread_mutex_t * mutex );

Description

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.

Returns

The pthread_mutex_destroy function returns zero if the call is successful, otherwise it sets errno and returns -1.

Implementation Notes

None.

14.7.3. The pthread_mutex_lock function

Synopsis
#include <pthread.h>

int pthread_mutex_lock (pthread_mutex_t * mutex );

Description

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.

Returns

The pthread_mutex_lock function returns zero if the call is successful, otherwise it sets errno to EINVAL and returns -1.

Implementation Notes

None.

14.7.4. The pthread_mutex_trylock function

Synopsis
#include <pthread.h>

int pthread_mutex_trylock (pthread_mutex_t * mutex );

Description

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.

Returns

The pthread_mutex_trylock function returns zero if the call is successful, otherwise it sets errno to EINVAL and returns -1.

Implementation Notes

None.

14.7.5. The pthread_mutex_unlock function

Synopsis
#include <pthread.h>

int pthread_mutex_unlock (pthread_mutex_t * mutex );

Description

The pthread_mutex_unlock function unlocks the given mutex.

Returns

The pthread_mutex_unlock function returns zero if the call is successful, otherwise it sets errno to EINVAL and returns -1.

Implementation Notes

None.