Linuxpthread_mutex_init () function

Source: Internet
Author: User
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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.