diff options
author | Rich Felker <dalias@aerifal.cx> | 2011-09-04 21:31:57 -0400 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2011-09-04 21:31:57 -0400 |
commit | 7493b57058af4c894dbda14924a2602ad30fd96a (patch) | |
tree | 1d145a001cc107b3ba5cd6537298d8f4b5d9a0ef | |
parent | a5794c5f7e452b28eed4cfaa33eca959574837f6 (diff) | |
download | libc-testsuite-7493b57058af4c894dbda14924a2602ad30fd96a.tar.gz |
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...
-rw-r--r-- | pthread.c | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -1,4 +1,5 @@ #include <pthread.h> +#include <semaphore.h> #include <stdlib.h> #include <unistd.h> #include <stdio.h> @@ -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"); |