From ccd91362dd6db79e1e652f2858ff8750a35192ff Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 17 Apr 2011 17:05:43 -0400 Subject: test nested cancellation handlers --- pthread.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/pthread.c b/pthread.c index dc1e74e..0fa8467 100644 --- a/pthread.c +++ b/pthread.c @@ -54,6 +54,37 @@ static void *start4(void *arg) return 0; } +static void cleanup4a2(void *arg) +{ + *(int *)arg += 2; +} + +static void cleanup4a3(void *arg) +{ + *(int *)arg += 3; + pthread_exit(0); +} + +static void cleanup4a4(void *arg) +{ + *(int *)arg += 4; +} + +static void *start4a(void *arg) +{ + int *foo = arg; + pthread_cleanup_push(cleanup4, foo); + pthread_cleanup_push(cleanup4a2, foo+1); + pthread_cleanup_push(cleanup4a3, foo+2); + pthread_cleanup_push(cleanup4a4, foo+3); + sleep(3); + pthread_cleanup_pop(0); + pthread_cleanup_pop(0); + pthread_cleanup_pop(0); + pthread_cleanup_pop(0); + return 0; +} + static void *start5(void *arg) { pthread_mutex_lock(arg); @@ -85,7 +116,7 @@ int test_pthread(void) int err = 0; int r; void *res; - int foo[2], bar[2]; + int foo[4], bar[2]; pthread_barrier_t barrier2; pthread_mutexattr_t mtx_a; pthread_mutex_t mtx, *sh_mtx; @@ -133,6 +164,17 @@ int test_pthread(void) TEST(res, res, PTHREAD_CANCELED, "canceled thread exit status"); TEST(r, foo[0], 1, "cleanup handler failed to run"); + /* Nested cleanup handlers */ + memset(foo, 0, sizeof foo); + TEST(r, pthread_create(&td, 0, start4a, foo), 0, "failed to create thread"); + TEST(r, pthread_cancel(td), 0, "cancelling"); + TEST(r, pthread_join(td, &res), 0, "joining canceled thread"); + TEST(res, res, 0, "canceled thread exit status"); + TEST(r, foo[0], 1, "cleanup handler failed to run"); + TEST(r, foo[1], 2, "cleanup handler failed to run"); + TEST(r, foo[2], 3, "cleanup handler failed to run"); + TEST(r, foo[3], 4, "cleanup handler failed to run"); + /* Robust mutexes */ TEST(r, pthread_mutexattr_init(&mtx_a), 0, "initializing mutex attr"); TEST(r, pthread_mutexattr_setrobust(&mtx_a, PTHREAD_MUTEX_ROBUST), 0, "setting robust attribute"); -- cgit v1.2.1