1 /* 2 * Copyright Andrey Semashev 2015. 3 * Distributed under the Boost Software License, Version 1.0. 4 * (See accompanying file LICENSE_1_0.txt or copy at 5 * http://www.boost.org/LICENSE_1_0.txt) 6 */ 7 8 #include <errno.h> 9 #include <pthread.h> 10 main(int,char * [])11int main(int, char*[]) 12 { 13 pthread_mutexattr_t attr; 14 pthread_mutexattr_init(&attr); 15 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL); 16 pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED); 17 pthread_mutexattr_setrobust(&attr, PTHREAD_MUTEX_ROBUST); 18 19 pthread_mutex_t m; 20 pthread_mutex_init(&m, &attr); 21 pthread_mutexattr_destroy(&attr); 22 23 int err = pthread_mutex_lock(&m); 24 if (err == EOWNERDEAD) 25 { 26 err = pthread_mutex_consistent(&m); 27 } 28 29 if (err != ENOTRECOVERABLE) 30 { 31 pthread_mutex_unlock(&m); 32 } 33 34 pthread_mutex_destroy(&m); 35 36 return 0; 37 } 38