Mutex Errors


The following programs demonstrate two misuses of mutexes: locking a mutex twice in a row; and unlocking a mutex when it is unlock. In a Linux, for a normal (default) mutex, the former case will result in deadlock, and the latter will not produce an error. Each program is followed by an identical program, but which sets the mutex's type to PTHREAD_MUTEX_ERRORCHECK so that the calls to pthread_mutex_lock and pthread_mutex_unlock return an error.

double_lock.c


      
double_lock_errocheck.c


      
unlock_without_locking.c


      
unlock_without_locking_errocheck.c


      

Additional files: