diff options
author | Rich Felker <dalias@aerifal.cx> | 2011-04-17 17:05:43 -0400 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2011-04-17 17:05:43 -0400 |
commit | ccd91362dd6db79e1e652f2858ff8750a35192ff (patch) | |
tree | 39d271b9468edf6836b390cda90d0bc6a022598a | |
parent | eb42b402487fa04778b62775fa200e35693fe59e (diff) | |
download | libc-testsuite-ccd91362dd6db79e1e652f2858ff8750a35192ff.tar.gz |
test nested cancellation handlers
-rw-r--r-- | pthread.c | 44 |
1 files changed, 43 insertions, 1 deletions
@@ -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"); |