pthread_mutex_init(3thr)
Name
pthread_mutex_init − Creates a mutex
Syntax
#include <pthread.h>
int pthread_mutex_init (mutex, attr)
pthread_mutex_t *mutex;
pthread_mutexattr_t attr;
Arguments
mutex Mutex created.
attr Mutex attributes object that defines the characteristics of the created mutex. If you specify pthread_mutexattr_default, default attributes are used.
Description
This routine creates a mutex. A mutex (mutual exclusion) is a synchronization object that allows multiple threads to serialize their access to shared data.
The mutex is created and initialized to the unlocked state.
The created mutex is not automatically deallocated because it is considered shared among multiple threads if the thread that called this routine terminates.
Return Values
If an error condition occurs, this routine returns -1, the mutex is not initialized, and the contents of mutex are undefined. This routine sets errno to the corresponding error value. Possible return values are as follows.
| Return | Error | Description |
| 0 | Successful completion. | |
| -1 | [EAGAIN] | The system lacks the necessary resources to initialize another mutex. |
| The system-imposed limit on the total number of mutexes under execution by a singled user is exceeded. | ||
| -1 | [ENOMEM] | Insufficient memory exists to initialize the mutex. |