pthread_mutexattr_settype()--Set Mutex Type Attribute
Syntax:
#include <pthread.h> int pthread_mutexatttr_settype(pthread_mutexattr_t *attr, int type);Service Program Name: QP0WPTHR
Default Public Authority: *USE
Threadsafe: Yes
Signal Safe: Yes
The pthread_mutexattr_settype() function sets the type attribute in the mutex attributes object specified by attr. The mutex type attribute is used to create mutexes with different behaviors.
The type will be one of PTHREAD_MUTEX_DEFAULT, PTHREAD_MUTEX_NORMAL, PTHREAD_MUTEX_RECURSIVE, PTHREAD_MUTEX_ERRORCHECK, or PTHREAD_MUTEX_OWNERTERM_NP or the EINVAL error will be returned.
The default mutex type (or PTHREAD_MUTEX_DEFAULT) is PTHREAD_MUTEX_NORMAL.
Mutex Types
A normal mutex cannot be locked repeatedly by the owner. Attempts by a thread to relock an already held mutex, or to lock a mutex that was held by another thread when that thread terminated result in a deadlock condition.
A recursive mutex can be locked repeatedly by the owner. The mutex does not become unlocked until the owner has called pthread_mutex_unlock() for each successful lock request that it has outstanding on the mutex.
An errorcheck mutex checks for deadlock conditions that occur when a thread re-locks an already held mutex. If a thread attempts to relock a mutex that it already holds, the lock request fails with the EDEADLK error.
An ownerterm mutex is an IBM® i extension to the errorcheck mutex type. An ownerterm mutex checks for deadlock conditions that occur when a thread re-locks an already held mutex. If a thread attempts to relock a mutex that it already holds, the lock request fails with the EDEADLK error. An ownerterm mutex also checks for deadlock conditions that occur when a thread attempts to lock a mutex that was held by another thread when that thread terminated (an orphaned mutex). If a thread attempts to lock an orphaned mutex, the lock request fails with the EOWNERTERM error.
Authorities and Locks
None.
Parameters
- attr
- (Input) Address of the mutex attributes object
- type
- (Input) Address of the type attribute to be set.
Return Value
- 0
- pthread_mutexattr_settype() was successful.
- value
- pthread_mutexattr_settype() was not successful. value is set to indicate the error condition.
Error Conditions
If pthread_mutexatttr_settype() was not successful, the error condition returned usually indicates one of the following errors. Under some conditions, the value returned could indicate an error other than those listed here.
- [EINVAL]
The value specified for the argument is not correct.
Related Information
- The <pthread.h> header file. See Header files for Pthread functions.
- pthread_mutexattr_gettype()--Get Mutex Type Attribute
- pthread_mutex_init()--Initialize Mutex
Example
See pthread_mutexattr_gettype() for an example.
API introduced: V4R3
[ Back to top | Pthread APIs | APIs by category ]