Mutex synchronization APIs
Thread synchronization is required whenever two threads share a resource or need to be aware of what the other threads in a process are doing. Mutexes are the most simple and primitive object used for the co-operative mutual exclusion required to share and protect resources. One thread owns a mutex by locking it successfully, when another thread tries to lock the mutex, that thread will not be allowed to successfully lock the mutex until the owner unlocks it. The mutex support provides different types and behaviors for mutexes that can be tuned to your application requirements.
The table below lists important mutex attributes, their default values, and all supported values.
Attribute | Default value | Supported values |
---|---|---|
pshared | PTHREAD_PROCESS_PRIVATE | PTHREAD_PROCESS_PRIVATE or PTHREAD_PROCESS_SHARED |
kind (non portable) | PTHREAD_MUTEX_NONRECURSIVE_NP | PTHREAD_MUTEX_NONRECURSIVE_NP or PTHREAD_MUTEX_RECURSIVE_NP |
name (non portable) | PTHREAD_DEFAULT_MUTEX_NAME_NP "QP0WMTX UNNAMED" | Any name that is 15 characters or less. If not terminated by a null character, name is truncated to 15 characters. |
type | PTHREAD_MUTEX_DEFAULT (PTHREAD_MUTEX_NORMAL) |
PTHREAD_MUTEX_DEFAULT or PTHREAD_MUTEX_NORMAL or PTHREAD_MUTEX_RECURSIVE or PTHREAD_MUTEX_ERRORCHECK or PTHREAD_MUTEX_OWNERTERM_NP The PTHREAD_MUTEX_OWNERTERM_NP attribute value is non portable. |
For information about the examples included with the APIs, see Information about the Pthread API examples.
The Mutex synchronization APIs are:
- pthread_lock_global_np() (Lock Global Mutex) locks a global mutex provided by the pthreads run-time.
- pthread_mutexattr_destroy() (Destroy Mutex Attributes Object) destroys a mutex attributes object and allows the system to reclaim any resources associated with that mutex attributes object.
- pthread_mutexattr_getkind_np() (Get Mutex Kind Attribute) retrieves the kind attribute from the mutex attributes object specified by attr.
- pthread_mutexattr_getname_np() (Get Name from Mutex Attributes Object) retrieves the name attribute associated with the mutex attribute specified by attr.
- pthread_mutexattr_getpshared() (Get Process Shared Attribute from Mutex Attributes Object) retrieves the current setting of the process shared attribute from the mutex attributes object.
- pthread_mutexattr_gettype() (Get Mutex Type Attribute) retrieves the type attribute from the mutex attributes object specified by attr.
- pthread_mutexattr_init() (Initialize Mutex Attributes Object) initializes the mutex attributes object referenced by attr to the default attributes.
- pthread_mutexattr_setkind_np() (Set Mutex Kind Attribute) sets the kind attribute in the mutex attributes object specified by attr.
- pthread_mutexattr_setname_np() (Set Name in Mutex Attributes Object) changes the name attribute associated with the mutex attribute specified by attr.
- pthread_mutexattr_setpshared() (Set Process Shared Attribute in Mutex Attributes Object) sets the current pshared attribute for the mutex attributes object.
- pthread_mutexattr_settype() (Set Mutex Type Attribute) sets the type attribute in the mutex attributes object specified by attr.
- pthread_mutex_destroy() (Destroy Mutex) destroys the named mutex.
- pthread_mutex_getname_np (Get Name from Mutex) retrieves the name of the specified mutex.
- pthread_mutex_init() (Initialize Mutex) initializes a mutex with the specified attributes for use.
- pthread_mutex_lock() (Lock Mutex) acquires ownership of the mutex specified.
- pthread_mutex_setname_np (Set Name in Mutex) sets the name of the specified mutex.
- pthread_mutex_timedlock_np() (Lock Mutex with Time-Out) acquires ownership of the mutex specified.
- pthread_mutex_trylock() (Lock Mutex with No Wait) attempts to acquire ownership of the mutex specified without blocking the calling thread.
- pthread_mutex_unlock() (Unlock Mutex) unlocks the mutex specified.
- pthread_set_mutexattr_default_np() (Set Default Mutex Attributes Object Kind Attribute) sets the kind attribute in the default mutex attribute object.
- pthread_unlock_global_np() (Unlock Global Mutex) unlocks a global mutex provided by the pthreads run-time.
[ Back to top | Pthread APIs | APIs by category ]