From 19299847fdd32094b28377db1aea61b0f605dc8b Mon Sep 17 00:00:00 2001 From: rpj Date: Sun, 1 Jul 2001 13:49:38 +0000 Subject: 2001-07-01 Ross Johnson Contributed by - Alexander Terekhov. * condvar.c: Fixed lost signal bug reported by Timur Aydin (taydin@snet.net). [RPJ (me) didn't translate the original algorithm correctly.] * semaphore.c: Added sem_post_multiple; this is a useful routine, but it doesn't appear to be standard. For now it's not an exported function. tests/ChangeLog: 2001-07-01 Ross Johnson * benchtest3.c: New; timing mutexes. * benchtest4.c: New; time mutexes. * condvar3_1.c: Fixed bug - Alexander Terekhov * condvar3_3.c: New test. 2001-06-25 Ross Johnson * priority1.c: New test. * priority2.c: New test. * inherit1.c: New test. * benchtest1.c: New; timing mutexes. * benchtest2.c: New; timing mutexes. * mutex4.c: Modified to test all mutex types. --- tests/condvar3_1.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'tests/condvar3_1.c') diff --git a/tests/condvar3_1.c b/tests/condvar3_1.c index f9bb0c6..ea5f33f 100644 --- a/tests/condvar3_1.c +++ b/tests/condvar3_1.c @@ -47,11 +47,13 @@ #include static pthread_cond_t cv; +static pthread_cond_t cv1; static pthread_mutex_t mutex; static struct timespec abstime = { 0, 0 }; static int timedout = 0; static int signaled = 0; static int awoken = 0; +static int waiting = 0; enum { NUMTHREADS = 60 @@ -64,6 +66,9 @@ mythread(void * arg) assert(pthread_mutex_lock(&mutex) == 0); + if ( ++waiting == NUMTHREADS) + assert(pthread_cond_signal(&cv1) == 0); + result = pthread_cond_timedwait(&cv, &mutex, &abstime); if (result == ETIMEDOUT) { @@ -91,6 +96,7 @@ main() const DWORD NANOSEC_PER_MILLISEC = 1000000; assert(pthread_cond_init(&cv, NULL) == 0); + assert(pthread_cond_init(&cv1, NULL) == 0); assert(pthread_mutex_init(&mutex, NULL) == 0); @@ -109,6 +115,10 @@ main() assert(pthread_create(&t[i], NULL, mythread, (void *) i) == 0); } + do { + assert(pthread_cond_wait(&cv1,&mutex) == 0); + } while ( NUMTHREADS != waiting ); + assert(pthread_mutex_unlock(&mutex) == 0); for (i = NUMTHREADS/3; i <= 2*NUMTHREADS/3; i++) @@ -120,9 +130,13 @@ main() for (i = 1; i <= NUMTHREADS; i++) { assert(pthread_join(t[i], (void **) &result) == 0); - assert(result == i); + assert(result == i); } + fprintf(stderr, "awk = %d\n", awoken); + fprintf(stderr, "sig = %d\n", signaled); + fprintf(stderr, "tot = %d\n", timedout); + assert(signaled == awoken); assert(timedout == NUMTHREADS - signaled); @@ -131,11 +145,11 @@ main() if (result != 0) { fprintf(stderr, "Result = %s\n", error_string[result]); - fprintf(stderr, "\tWaitersBlocked = %ld\n", cv->nWaitersBlocked); - fprintf(stderr, "\tWaitersUnblocked = %ld\n", cv->nWaitersUnblocked); - fprintf(stderr, "\tWaitersGone = %ld\n", cv->nWaitersGone); - fprintf(stderr, "\tWaitersToUnblock = %ld\n", cv->nWaitersToUnblock); - fflush(stderr); + fprintf(stderr, "\tWaitersBlocked = %ld\n", cv->nWaitersBlocked); + fprintf(stderr, "\tWaitersUnblocked = %ld\n", cv->nWaitersUnblocked); + fprintf(stderr, "\tWaitersGone = %ld\n", cv->nWaitersGone); + fprintf(stderr, "\tWaitersToUnblock = %ld\n", cv->nWaitersToUnblock); + fflush(stderr); } assert(result == 0); } -- cgit v1.2.3