summaryrefslogtreecommitdiff
path: root/tests/condvar3_1.c
diff options
context:
space:
mode:
authorrpj <rpj>2001-07-01 13:49:38 +0000
committerrpj <rpj>2001-07-01 13:49:38 +0000
commit19299847fdd32094b28377db1aea61b0f605dc8b (patch)
tree6790f92e1c0d67063edccf82a57616f977633aef /tests/condvar3_1.c
parenta311086d622d3c778e1da57cfae167c0ab1c0fb4 (diff)
2001-07-01 Ross Johnson <rpj@setup1.ise.canberra.edu.au>
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 <rpj@special.ise.canberra.edu.au> * 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 <rpj@special.ise.canberra.edu.au> * 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.
Diffstat (limited to 'tests/condvar3_1.c')
-rw-r--r--tests/condvar3_1.c26
1 files changed, 20 insertions, 6 deletions
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 <sys/timeb.h>
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);
}