Thread Synchronization
Mutex - “Mutual Exclusion”
Attributes
- int pthread_mutexattr_init(pthreads_mutexattr_t * attr);
- int pthread_mutexattr_destroy( pthreads_mutexattr_t * attr);
- int pthread_mutexattr_getpshared(pthreads_mutexattr_t *attr, int *pshared);
- int pthread_mutexattr_setpshared(pthreads_mutexattr_t *attr, int pshared);
- PTHREAD_PROCESS_PRIVATE, PTHREAD_PROCESS_SHARED;
Initialization and Destruction
- Static Init: pthread_mutex_t foo = PTHREAD_MUTEX_INITIALIZER;
- Mutex is constructed with system default attributes.
- Dynamic Init:
- int pthread_mutex_init(pthread_mutex_t *mtx, pthread_mutexattr_t *attr);
- Constructed with attributes in attr
- Destruction: int pthread_mutex_destroy(pthread_mutex *mutex);
Author | Title | Tracks | Home