Linux thread Lock

Source: Internet
Author: User

1. Mutex: Mutex

A. For mutex Access B. Type: pthread_mutex_t, must be initialized to Pthread_mutex_initializer (for statically assigned mutex, equivalent to Pthread_mutex_init (..., NULL) ) or call Pthread_mutex_init. Mutexes should also be destroyed with Pthread_mutex_destroy.  #i nclude <pthread.h>1) int pthread_mutex_init (       pthread_mutex_t * Restrict mutex,       const pthread_mutexattr_t *restrict attr); function pthread_mutex_ Init is used to generate a mutex, the null parameter indicates that the default property is used, and if a mutex for a particular property needs to be declared, the function Pthread_mutexattr_init must be called. Function pthread_mutexattr_setpshared and functions The Pthread_mutexattr_settype is used to set the Mutex property. The previous function sets the property pshared, which has two values, pthread_process_private, and pthread_process_shared. The former is used for thread synchronization in different processes, and the latter is used to synchronize different threads of the process.  2) int Pthread_mutex_destroy (pthread_mutex_t *mutex);  3) int pthread_mutex_lock (pthread_mutex_t *mutex);  4) int Pthread_mutex_trylock (pthread_mutex_t *mutex);  5) int pthread_mutex_unlock (pthread_mutex_t *mutex) ;      2.conditional Variable: Condition A. The condition must be protected by a mutex B. Type: pthread_cond_t, must be initialized to Pthread_ Cond_initializer (for statically assigned conditions, equivalent to PThread_cond_init (..., NULL)) or call pthread_cond_init#i nclude <pthread.h>1) int Pthread_cond_init (        pthread_cond_t *restrict cond,       const PTHREAD_CONDXATTR _t *restrict attr)  2) int Pthread_cond_destroy (pthread_cond_t *cond);  3) int pthread_cond_wait (        pthread_cond_t *restrict cond,       pthread_mutex_t * Restrict mutex);  4) int pthread_cond_timedwait (       pthread_cond_t *restrict cond,       pthread_mutex_t *restrict mutex,       const struct TIMESPEC *restrict timeout);  5) int pthread_cond_signal (pthread_cond_t *cond);  6) int Pthread_ Cond_broadcast (pthread_cond_t *cond);       

Linux thread lock

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.