linux mutex

Mutex (mutex) is essentially a lock, a lock on the mutex before accessing a shared resource, mutex lock on the access after release.

After the conduct of the mutex lock, trying again to any other mutex lock the thread will be blocked until the current thread releases the mutex. If there are multiple threads blocked release the mutex, all threads are blocked on the mutex lock into an operable state. The first became operational state of the thread can lock the mutex, the other threads will still see the mutex is locked, it can only go back and wait again becomes available again.

 

It should be clear:

Mutex is mainly used for mutually exclusive , describes a competitive relationship, the main resource or a code in a period of time up to a program can be accessed.

Linux mutex in general has the following functions:

int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr);
int pthread_mutex_lock(pthread_mutex_t *mutex);
int pthread_mutex_trylock(pthread_mutex_t *mutex);
int pthread_mutex_unlock(pthread_mutex_t *mutex);
int pthread_mutex_destroy(pthread_mutex_t *mutex);

 

Guess you like

Origin www.cnblogs.com/caidi/p/11310274.html
Recommended