If you unlock an already unlocked mutex, is the behavior unsafe, safe, or undefined?
The purpose of the question is related to the following code, where I don\'t kno
Try it. This is code working correct.
// Mutex is not busy
if(pthread_mutex_trylock(&object->mtx) == 0) {
if(pthread_mutex_unlock(&object->mtx)!=0) {
perror("ERRN: pthread_mutex_unlock:");
}
}
// Mutex is already busy
else {
if(pthread_mutex_unlock(&object->mtx)!=0) {
perror("ERRN: pthread_mutex_unlock:");
}
}
// In this point -- we correctly unlocked mutex.
if(pthread_mutex_destroy(&object->mtx) != 0) {
perror("ERRN: pthread_mutex_destroy:");
}