Function prototype: Intpthread_mutex_init (pthread_mutex_t * restrict_mutex, constpthread_mutextattr_t * restrictattr) this function is mainly used to initialize mutex locks in multiple threads. If attr is null, it is the default attribute, and the default attribute is... 
Function prototype: Int pthread_mutex_init (pthread_mutex_t * restrict_mutex, const pthread_mutextattr_t * restrict attr)
This function is used to initialize mutex locks in multiple threads.
If attr is null, it is the default attribute, and the quick mutex lock of the default attribute.
After pthread_mutex_init is successful, 0 is returned. other values are incorrect.
Int pthread_mutextattr_destroy (pthread_mutextattr_t * restrict_mutext)
This function is used to destroy the thread mutex lock.
Set the scope of the mutex lock:
Int pthread_mutextattr_setpshared (pthread_mutexattr_t * restrict mutext, int pshared)
Mutual exclusion locks are shared in multiple threads.
If you want to share the mutex lock among multiple processes, you can set PTHREAD_PROCESS_SHARED for pshared.
If you only want to share the mutex lock in the thread created by the same process, you can set pshared to PTHREAD_PROCESS_PRIVATE.
Obtain the scope of the mutex lock:
Int pthread_mutexattr_getpshared (pthread_mutexattr_t * restrict mutext, int * pshared );
Set mutex lock type attributes:
Int pthread_mutexattr_settype (pthread_mutexattr_t * restrict mutext, int type)
The type types include:
PTHREAD_MUTEX_NOMRAL: this type of mutex lock does not detect deadlocks.
The default value is PTHREAD_MUTEX_DEFAULT.
PTHREAD_MUTEX_ERRORCHECK: Error Check is provided
Int pthread_mutexattr_setprotocal (pthread_mutexattr_t * attr, int protocal)
Protocols that can set mutex lock attributes
PTHREAD_PRIO_NONE
PTHREAD_PRIO_INHERIT
PTHREAD_PRIO_PROTECT
 
Author: "dancer blog"