pthread_mutex_init()

initialize a mutex 

Function


SYNOPSIS

#include <pthread.h>

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


DESCRIPTION

The pthread_mutex_init() function initializes the specified mutex. If attr is non-NULL, the attributes specified are used to initialize the mutex. If the attribute object is modified later, the mutex's attributes are not affected. If attr is NULL, the mutex is initialized with default attributes, as specified for pthread_mutexattr_init().

A mutex can be statically initialized by assigning PTHREAD_MUTEX_INITIALIZER in its definition, as follows:

pthread_mutex_t def_mutex = PTHREAD_MUTEX_INITIALIZER;

A mutex must be initialized (either by calling pthread_mutex_init(), or statically) before it may be used in any other mutex functions.


PARAMETERS

mutex 

Is the mutex to initialize.

attr 

Specifies the attributes to use to initialize the mutex, or NULL if default attributes should be used.


RETURN VALUES

On success, pthread_mutex_init() returns 0. On error, one of the following values is returned:

EAGAIN 

System resources (other than memory) are unavailable.

EINVAL 

attr does not refer to a valid condition variable attribute object.

EFAULT 

mutex or attr is an invalid pointer.

ENOMEM 

Insufficient memory exists to initialize the mutex.


CONFORMANCE

POSIX P1003.1 (1996)


MULTITHREAD SAFETY LEVEL

MT-safe.


PORTING ISSUES

None.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
pthread_mutex_destroy(), pthread_mutexattr_init()


PTC MKS Toolkit 10.3 Documentation Build 39.