pthread_mutex_init Subroutine Purpose Initializes a mutex and sets its attributes. Library Threads Library (libpthreads.a) Syntax #include int pthread_mutex_init (mutex, attr) pthread_mutex_t *mutex; pthread_mutexattr_t *attr; Description The pthread_mutex_init subroutine initializes a new mutex mutex, and sets its attributes according the mutex attributes object attr. The mutex is initially unlocked. After initialization of the mutex, the mutex attributes object can be reused for another mutex initialization, or deleted. Note: The pthread.h header file must be the first included file of each source file using the threads library. Parameters mutex Specifies the mutex to be created. attr Specifes the mutex attributes object to use for initializing the mutex. If the value is NULL, the default attributes values are used. Return Values Upon successful completion, the new mutex is returned via the mutex parameter, and 0 is returned. Otherwise, an error code is returned. Error Codes The pthread_mutex_init subroutine is unsuccessful if the following is true: EAGAIN The system does not have sufficient resources, other than memory, to initialize a new mutex. EBUSY The mutex mutex is already in use: it was previously created with by calling the pthread_mutex_init subroutine, and not destroyed by calling the pthread_mutex_destroy subroutine. EINVAL The mutex or attr parameters are not valid. ENOMEM There is not sufficient memory to initialize a new mutex. Implementation Specifics This subroutine is part of the Base Operating System (BOS) Runtime. Related Information The pthread_mutexattr_init subroutine, pthread_mutexattr_destroy subroutine, pthread_mutex_lock or pthread_mutex_trylock subroutine, pthread_mutex_destroy subroutine, PTHREAD_MUTEX_INITIALIZER macro. Using Mutexes. Threads Library Quick Reference.