[Return to Bookshelf] [Contents] [Previous Section] [Next Section] [Index] [Help]


pthread_mutex_init

Creates a mutex.

Syntax

pthread_mutex_init(
                   mutex,
                   attr );
 


Argument Data Type Access

mutex opaque pthread_mutex_t write attr opaque pthread_ read mutexattr_t


C Binding

int
pthread_mutex_init (
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 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.



[Return to Bookshelf] [Contents] [Previous Section] [Next Section] [Index] [Help]