diff options
author | Rich Felker <dalias@aerifal.cx> | 2011-09-22 21:09:56 -0400 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2011-09-22 21:09:56 -0400 |
commit | 013c2f7aa49f5b683ff28f5e039287cba960e3d6 (patch) | |
tree | 0bf01e0922096fecbf6f9e8306e4e32c44b856b4 | |
parent | 8c298bf215b6ce155df86e82f48344a3b7518225 (diff) | |
download | libc-testsuite-013c2f7aa49f5b683ff28f5e039287cba960e3d6.tar.gz |
new pthread cond var test for multiple waiters
-rw-r--r-- | pthread.c | 43 |
1 files changed, 42 insertions, 1 deletions
@@ -109,10 +109,24 @@ static void *start7(void *arg) return 0; } +static void *start8(void *arg) +{ + void **args = arg; + pthread_mutex_t *m = args[1]; + pthread_cond_t *c = args[0]; + int *x = args[2]; + + pthread_mutex_lock(m); + while (*x) pthread_cond_wait(c, m); + pthread_mutex_unlock(m); + + return 0; +} + int test_pthread(void) { - pthread_t td; + pthread_t td, td1, td2, td3; int err = 0; int r; void *res; @@ -222,5 +236,32 @@ int test_pthread(void) TEST(r, pthread_mutex_destroy(&mtx), 0, "%d != %d"); TEST(r, pthread_cond_destroy(&cond), 0, "%d != %d"); + + 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"); + foo[0] = 1; + TEST(r, pthread_create(&td1, 0, start8, (void *[]){ &cond, &mtx, foo }), 0, "%d != %d"); + TEST(r, pthread_create(&td2, 0, start8, (void *[]){ &cond, &mtx, foo }), 0, "%d != %d"); + TEST(r, pthread_create(&td3, 0, start8, (void *[]){ &cond, &mtx, foo }), 0, "%d != %d"); + TEST(r, pthread_mutex_unlock(&mtx), 0, "%d != %d"); + nanosleep(&(struct timespec){.tv_nsec=1000000}, 0); + foo[0] = 0; + TEST(r, pthread_mutex_lock(&mtx), 0, "%d != %d"); + TEST(r, pthread_cond_signal(&cond), 0, "%d != %d"); + TEST(r, pthread_mutex_unlock(&mtx), 0, "%d != %d"); + TEST(r, pthread_mutex_lock(&mtx), 0, "%d != %d"); + TEST(r, pthread_cond_signal(&cond), 0, "%d != %d"); + TEST(r, pthread_mutex_unlock(&mtx), 0, "%d != %d"); + TEST(r, pthread_mutex_lock(&mtx), 0, "%d != %d"); + TEST(r, pthread_cond_signal(&cond), 0, "%d != %d"); + TEST(r, pthread_mutex_unlock(&mtx), 0, "%d != %d"); + TEST(r, pthread_join(td1, 0), 0, "%d != %d"); + TEST(r, pthread_join(td2, 0), 0, "%d != %d"); + TEST(r, pthread_join(td3, 0), 0, "%d != %d"); + TEST(r, pthread_mutex_destroy(&mtx), 0, "%d != %d"); + TEST(r, pthread_cond_destroy(&cond), 0, "%d != %d"); + + return err; } |