summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-03-28 23:01:42 -0400
committerRich Felker <dalias@aerifal.cx>2011-03-28 23:01:42 -0400
commit22ec3cfd85228b6910f2f6b61626eb13c14636d7 (patch)
tree088a291d0aceeb29715ff7c38a4e3f43f1414b37
parentead84f05c3116fec519a27be776b1206416195d9 (diff)
downloadlibc-testsuite-22ec3cfd85228b6910f2f6b61626eb13c14636d7.tar.gz
primitive condition var test
-rw-r--r--pthread.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/pthread.c b/pthread.c
index 14fbc4a..a851340 100644
--- a/pthread.c
+++ b/pthread.c
@@ -69,6 +69,15 @@ static void *start6(void *arg)
return 0;
}
+static void *start7(void *arg)
+{
+ void **args = arg;
+ pthread_mutex_lock(args[1]);
+ pthread_cond_signal(args[0]);
+ pthread_mutex_unlock(args[1]);
+ return 0;
+}
+
int test_pthread(void)
{
@@ -80,6 +89,7 @@ int test_pthread(void)
pthread_barrier_t barrier2;
pthread_mutexattr_t mtx_a;
pthread_mutex_t mtx, *sh_mtx;
+ pthread_cond_t cond;
int fd;
TEST(r, pthread_barrier_init(&barrier2, 0, 2), 0, "creating barrier");
@@ -157,5 +167,16 @@ int test_pthread(void)
//TEST(r, (fd=open("/dev/zero", O_RDWR))>=0, 1, "opening zero page file");
//TEST(r,
+ /* Condition variables */
+ TEST(r, pthread_mutex_init(&mtx, 0), 0, "%d != %d");
+ TEST(r, pthread_cond_init(&cond, 0), 0, "%d != %d");
+ TEST(r, pthread_mutex_lock(&mtx), 0, "%d != %d");
+ TEST(r, pthread_create(&td, 0, start7, (void *[]){ &cond, &mtx }), 0, "%d != %d");
+ TEST(r, pthread_cond_wait(&cond, &mtx), 0, "%d != %d");
+ TEST(r, pthread_join(td, &res), 0, "%d != %d");
+ TEST(r, pthread_mutex_unlock(&mtx), 0, "%d != %d");
+ TEST(r, pthread_mutex_destroy(&mtx), 0, "%d != %d");
+ TEST(r, pthread_cond_destroy(&cond), 0, "%d != %d");
+
return err;
}