From 7493b57058af4c894dbda14924a2602ad30fd96a Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 4 Sep 2011 21:31:57 -0400 Subject: fix pthread test: cannot use barriers with async cancellation enabled! actually, sem_post is not specified as being async-canel-safe either, but it's required to be async-signal-safe, and if it did anything unsafe after upping the semaphore value, there's no way it could be async-signal-safe... --- pthread.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pthread.c b/pthread.c index 12533fa..b3977a5 100644 --- a/pthread.c +++ b/pthread.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -36,7 +37,7 @@ static void *start2(void *arg) static void *start3(void *arg) { pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0); - pthread_barrier_wait(arg); + sem_post(arg); for (;;); return 0; } @@ -120,9 +121,11 @@ int test_pthread(void) pthread_mutexattr_t mtx_a; pthread_mutex_t mtx, *sh_mtx; pthread_cond_t cond; + sem_t sem1; int fd; TEST(r, pthread_barrier_init(&barrier2, 0, 2), 0, "creating barrier"); + TEST(r, sem_init(&sem1, 0, 0), 0, "creating semaphore"); /* Test basic thread creation and joining */ TEST(r, pthread_create(&td, 0, start1, &res), 0, "failed to create thread"); @@ -149,8 +152,8 @@ int test_pthread(void) TEST(r, pthread_key_delete(k2), 0, "failed to destroy key"); /* Asynchronous cancellation */ - TEST(r, pthread_create(&td, 0, start3, &barrier2), 0, "failed to create thread"); - pthread_barrier_wait(&barrier2); + TEST(r, pthread_create(&td, 0, start3, &sem1), 0, "failed to create thread"); + while (sem_wait(&sem1)); TEST(r, pthread_cancel(td), 0, "canceling"); TEST(r, pthread_join(td, &res), 0, "joining canceled thread"); TEST(res, res, PTHREAD_CANCELED, "canceled thread exit status"); -- cgit v1.2.1