From bdf66f88ab2a2fc05a86900bd72de0f77905e4db Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Thu, 18 Jun 2015 22:19:55 +0000 Subject: [PATCH] run robust-detach test for pshared and non-pshared mutex --- src/regression/pthread-robust-detach.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/regression/pthread-robust-detach.c b/src/regression/pthread-robust-detach.c index 9c2c3bf..ec772da 100644 --- a/src/regression/pthread-robust-detach.c +++ b/src/regression/pthread-robust-detach.c @@ -6,10 +6,12 @@ #include #include "test.h" -#define TX(r,f,x) ( ((r)=(f))==x || (t_error(#f" failed: got %d \"%s\" want %d \"%s\"\n", r, strerror(r), x, strerror(x)), 0) ) +#define TX(r,f,x) ( ((r)=(f))==x || \ + (t_error(#f" failed: (pshared==%d) got %d \"%s\" want %d \"%s\"\n", pshared, r, strerror(r), x, strerror(x)), 0) ) #define T(r,f) TX(r,f,0) static pthread_barrier_t barrier2; +static int pshared; static void *start_lock(void *arg) { @@ -18,7 +20,7 @@ static void *start_lock(void *arg) return 0; } -int main(void) +static void f() { pthread_t td; int r; @@ -29,13 +31,15 @@ int main(void) T(r, pthread_barrier_init(&barrier2, 0, 2)); T(r, pthread_mutexattr_init(&mtx_a)); T(r, pthread_mutexattr_setrobust(&mtx_a, PTHREAD_MUTEX_ROBUST)); - T(r, pthread_mutexattr_setpshared(&mtx_a, PTHREAD_PROCESS_SHARED)); + if (pshared) + T(r, pthread_mutexattr_setpshared(&mtx_a, PTHREAD_PROCESS_SHARED)); T(r, pthread_mutex_init(&mtx, &mtx_a)); T(r, pthread_create(&td, 0, start_lock, &mtx)); T(r, pthread_detach(td)); pthread_barrier_wait(&barrier2); + pthread_barrier_destroy(&barrier2); - // enough time to ensure that the other thread is dead + // enough time to ensure that the detached thread is dead clock_gettime(CLOCK_REALTIME, &ts); ts.tv_nsec += 100*1000*1000; if (ts.tv_nsec >= 1000*1000*1000) { @@ -44,5 +48,13 @@ int main(void) } TX(r, pthread_mutex_timedlock(&mtx, &ts), EOWNERDEAD); +} + +int main(void) +{ + // test non-pshared and pshared robust mutexes as well + f(); + pshared = 1; + f(); return t_status; } -- 2.11.4.GIT