In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/bb09c94c3bb1638714998511ecf5d337a708535a?hp=b4ffc3db31e268adb50c44bab9b628dc619f1e83>
- Log ----------------------------------------------------------------- commit bb09c94c3bb1638714998511ecf5d337a708535a Author: David Mitchell <[email protected]> Date: Fri Apr 15 10:17:07 2011 +0100 stop waithires.t failing under high load In threads::shared, the waithires.t test checks cond_timedwait() with sub-second timeouts. If the newly-minted child doesn't manage to grab the lock within 0.05s, the cond_timedwait() will timeout, and the child and the test will hang, until eventually killed off by the watchdog. This can easily happen on a slow/loaded system. We fix this by putting the cond_timedwait() in a retry loop, only giving up after 10 seconds of repeated timeouts. ----------------------------------------------------------------------- Summary of changes: dist/threads-shared/t/waithires.t | 30 ++++++++++++++++++++++++------ 1 files changed, 24 insertions(+), 6 deletions(-) diff --git a/dist/threads-shared/t/waithires.t b/dist/threads-shared/t/waithires.t index e3a1086..3c3e852 100644 --- a/dist/threads-shared/t/waithires.t +++ b/dist/threads-shared/t/waithires.t @@ -70,6 +70,24 @@ my @wait_how = ( "twain" # cond var != lock var; explicit lock; e.g.: cond_wait($c, $l) ); +# run cond_timedwait, and repeat if it times out (give up after 10 secs) + +sub cond_timedwaitN { + my $ok; + my $end = time() + 10; + while (1) { + if (@_ == 3) { + $ok = cond_timedwait($_[0], $_[1], $_[2]); + } + else { + $ok = cond_timedwait($_[0], $_[1]); + } + last if $ok; + last if time() > $end; + } + return $ok; +} + SYNC_SHARED: { my $test_type :shared; # simple|repeat|twain @@ -111,9 +129,9 @@ SYNC_SHARED: { my $thr = threads->create(\&signaller, $testnum); my $ok = 0; for ($test_type) { - $ok = cond_timedwait($cond, time() + $to), last if /simple/; - $ok = cond_timedwait($cond, time() + $to, $cond), last if /repeat/; - $ok = cond_timedwait($cond, time() + $to, $lock), last if /twain/; + $ok = cond_timedwaitN($cond, time() + $to), last if /simple/; + $ok = cond_timedwaitN($cond, time() + $to, $cond), last if /repeat/; + $ok = cond_timedwaitN($cond, time() + $to, $lock), last if /twain/; die "$test_type: unknown test\n"; } $testnum = $thr->join(); @@ -215,9 +233,9 @@ SYNCH_REFS: { my $thr = threads->create(\&signaller2, $testnum); my $ok = 0; for ($test_type) { - $ok = cond_timedwait($cond, time() + $to), last if /simple/; - $ok = cond_timedwait($cond, time() + $to, $cond), last if /repeat/; - $ok = cond_timedwait($cond, time() + $to, $lock), last if /twain/; + $ok = cond_timedwaitN($cond, time() + $to), last if /simple/; + $ok = cond_timedwaitN($cond, time() + $to, $cond), last if /repeat/; + $ok = cond_timedwaitN($cond, time() + $to, $lock), last if /twain/; die "$test_type: unknown test\n"; } $testnum = $thr->join(); -- Perl5 Master Repository
