NAME

pthread_mutexattr_init, pthread_mutexattr_settype, pthread_mutexattr_gettype, pthread_mutexattr_destroy - mutex attributes control

SYNOPSIS

#include <pthread.h>

int pthread_mutexattr_init(pthread_mutexattr_t *attr);
int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type);
int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *type);
int pthread_mutexattr_destroy(pthread_mutexattr_t *attr);

DESCRIPTION

The pthread_mutexattr_init() function initializes a mutex attributes object attr with the default values.

The pthread_mutexattr_destroy() function destroys a mutex attributes object attr.

The pthread_mutexattr_gettype() and pthread_mutexattr_settype() functions, respectively, get and set the mutex type attribute. This attribute is set in the type parameter to these functions. The default value of the type attribute is PTHREAD_MUTEX_DEFAULT.

The type of mutex is contained in the type attribute of the mutex attributes. Valid mutex types include:

PTHREAD_MUTEX_NORMAL
A normal type mutex does not detect deadlock. Attempting to relock the mutex causes deadlock. The mutex is either in a locked or unlocked state for a thread.
PTHREAD_MUTEX_ERRORCHECK
An errorcheck type mutex provides error checking. If a thread attempts to relock a mutex that it has already locked, an error will be returned. If a thread attempts to unlock a mutex and the thread in not the owner of the mutex, an error will be returned.
PTHREAD_MUTEX_RECURSIVE
A recursive type mutex permits a thread to lock many times. When a thread successfully acquires a mutex for the first time, the lock count will be set to one. Every time a thread relocks this mutex, the lock count will be incremented by one. Each time the thread unlocks the mutex, the lock count will be decremented by one. When the lock count reaches zero, the mutex will become available for other threads to acquire. If a thread attempts to unlock a mutex and the thread in not the owner of the mutex, an error will be returned.
PTHREAD_MUTEX_DEFAULT
The default type mutex is mapped to a normal type mutex.

RETURN VALUES

If successful, all of these functions return 0 ; otherwise, an error number is returned.

ERRORS

pthread_mutexattr_init() fails and returns the corresponding value if any of the following conditions occur:

ENOMEM
Insufficient memory exists to initialize the mutex attributes object.

pthread_mutexattr_gettype(), pthread_mutexattr_settype() and pthread_mutexattr_destroy() fail and return the corresponding value if any of the following conditions occur:

EINVAL
The attr is invalid pointer or type has wrong parameter.

SEE ALSO

mutex

Home page (Kernel)


< Copyright Rowebots Research Inc. and Multiprocessor Toolsmiths Inc. 1987-2018 >