From e367976ddeaf7141f041d12f42725652cbaa2b7b Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 9 Nov 2004 14:58:02 +0000 Subject: [PATCH] Improve pth_cvsimple test in two ways: 1. Make the output deterministic; different thread interleaving from expected was causing failures for me. 2. Make it actually use the condition variable -- the condvar stupidly wasn't actually being used in the expected case, because the other threads finished all their work before pthread_cond_wait() even got called, and this prevented the condition guarding pthread_cond_wait() from succeeding. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2952 --- corecheck/tests/pth_cvsimple.c | 37 ++++++++++++--------- corecheck/tests/pth_cvsimple.stdout.exp | 44 ++++++++++++------------- 2 files changed, 44 insertions(+), 37 deletions(-) diff --git a/corecheck/tests/pth_cvsimple.c b/corecheck/tests/pth_cvsimple.c index 3bb5085f8..f525e3623 100644 --- a/corecheck/tests/pth_cvsimple.c +++ b/corecheck/tests/pth_cvsimple.c @@ -9,7 +9,7 @@ * * cvsimple.c * - * Demonstrates pthread cancellation. + * Demonstrates pthread condvars. * */ @@ -20,23 +20,22 @@ #define TCOUNT 10 #define COUNT_THRES 12 +int condvar_was_hit = 0; int count = 0; int thread_ids[3] = {0,1,2}; pthread_mutex_t count_lock=PTHREAD_MUTEX_INITIALIZER; pthread_cond_t count_hit_threshold=PTHREAD_COND_INITIALIZER; -void *inc_count(void *idp) +void *inc_count(void *null) { int i=0; - int *my_id = idp; for (i=0; i 1) + printf("condvar was multi-hit...\n"); + else + printf("condvar was missed...\n"); + return 0; } diff --git a/corecheck/tests/pth_cvsimple.stdout.exp b/corecheck/tests/pth_cvsimple.stdout.exp index 92dab19ed..b843163bc 100644 --- a/corecheck/tests/pth_cvsimple.stdout.exp +++ b/corecheck/tests/pth_cvsimple.stdout.exp @@ -1,22 +1,22 @@ -inc_counter(): thread 0, count = 1, unlocking mutex -inc_counter(): thread 0, count = 2, unlocking mutex -inc_counter(): thread 0, count = 3, unlocking mutex -inc_counter(): thread 0, count = 4, unlocking mutex -inc_counter(): thread 0, count = 5, unlocking mutex -inc_counter(): thread 0, count = 6, unlocking mutex -inc_counter(): thread 0, count = 7, unlocking mutex -inc_counter(): thread 0, count = 8, unlocking mutex -inc_counter(): thread 0, count = 9, unlocking mutex -inc_counter(): thread 0, count = 10, unlocking mutex -inc_counter(): thread 1, count = 11, unlocking mutex -inc_counter(): thread 1, count = 12, unlocking mutex -inc_count(): Thread 1, count 12 -inc_counter(): thread 1, count = 13, unlocking mutex -inc_counter(): thread 1, count = 14, unlocking mutex -inc_counter(): thread 1, count = 15, unlocking mutex -inc_counter(): thread 1, count = 16, unlocking mutex -inc_counter(): thread 1, count = 17, unlocking mutex -inc_counter(): thread 1, count = 18, unlocking mutex -inc_counter(): thread 1, count = 19, unlocking mutex -inc_counter(): thread 1, count = 20, unlocking mutex -watch_count(): thread 2 +inc_counter(): count = 1, unlocking mutex +inc_counter(): count = 2, unlocking mutex +inc_counter(): count = 3, unlocking mutex +inc_counter(): count = 4, unlocking mutex +inc_counter(): count = 5, unlocking mutex +inc_counter(): count = 6, unlocking mutex +inc_counter(): count = 7, unlocking mutex +inc_counter(): count = 8, unlocking mutex +inc_counter(): count = 9, unlocking mutex +inc_counter(): count = 10, unlocking mutex +inc_counter(): count = 11, unlocking mutex +inc_counter(): count = 12, unlocking mutex +hit threshold! +inc_counter(): count = 13, unlocking mutex +inc_counter(): count = 14, unlocking mutex +inc_counter(): count = 15, unlocking mutex +inc_counter(): count = 16, unlocking mutex +inc_counter(): count = 17, unlocking mutex +inc_counter(): count = 18, unlocking mutex +inc_counter(): count = 19, unlocking mutex +inc_counter(): count = 20, unlocking mutex +condvar was hit!