For mutexes shared between processes ( PTHREAD_PROCESS_SHARED), you can set them PTHREAD_MUTEX_ROBUST... but you are stuck in the problem that the state protected by the mutex might be invalid - depending on the application.
For mutexes that are not shared between processes, there is no standard concept of "reliability", since a thread cannot spontaneously die on its own - a thread will work until it is canceled, it will not exit, or the process will not end or die.
:
void pthread_cleanup_push(void (*routine)(void*), void *arg);
void pthread_cleanup_pop(int execute);
, , - - :
pthread_mutex_lock(&foo) ;
pthread_cleanup_push(pthread_mutex_unlock, &foo) ;
....
pthread_cleanup_pop(true) ;
: , , , !!
, , , , /, / ( ).
user3793679