1 // commit 12e1e324683a1d381b7f15dd36c99b37dd44d940 2015-04-10
2 // robust mutex should work with detached threads too
9 #define TX(r,f,x) ( ((r)=(f))==x || \
10 (t_error(#f" failed: (pshared==%d) got %d \"%s\" want %d \"%s\"\n", pshared, r, strerror(r), x, strerror(x)), 0) )
11 #define T(r,f) TX(r,f,0)
13 static pthread_barrier_t barrier2
;
16 static void *start_lock(void *arg
)
18 pthread_mutex_lock(arg
);
19 pthread_barrier_wait(&barrier2
);
27 pthread_mutexattr_t mtx_a
;
31 T(r
, pthread_barrier_init(&barrier2
, 0, 2));
32 T(r
, pthread_mutexattr_init(&mtx_a
));
33 T(r
, pthread_mutexattr_setrobust(&mtx_a
, PTHREAD_MUTEX_ROBUST
));
35 T(r
, pthread_mutexattr_setpshared(&mtx_a
, PTHREAD_PROCESS_SHARED
));
36 T(r
, pthread_mutex_init(&mtx
, &mtx_a
));
37 T(r
, pthread_create(&td
, 0, start_lock
, &mtx
));
38 T(r
, pthread_detach(td
));
39 pthread_barrier_wait(&barrier2
);
40 pthread_barrier_destroy(&barrier2
);
42 // enough time to ensure that the detached thread is dead
43 clock_gettime(CLOCK_REALTIME
, &ts
);
44 ts
.tv_nsec
+= 100*1000*1000;
45 if (ts
.tv_nsec
>= 1000*1000*1000) {
47 ts
.tv_nsec
-= 1000*1000*1000;
50 TX(r
, pthread_mutex_timedlock(&mtx
, &ts
), EOWNERDEAD
);
55 // test non-pshared and pshared robust mutexes as well