summaryrefslogtreecommitdiff
path: root/pthread.c
diff options
context:
space:
mode:
Diffstat (limited to 'pthread.c')
-rw-r--r--pthread.c9
1 files 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 <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");