--- Coro/t/15_semaphore.t 2008/11/16 09:43:18 1.2 +++ Coro/t/15_semaphore.t 2008/11/16 10:33:08 1.3 @@ -4,33 +4,35 @@ use Coro; use Coro::Semaphore; -my $sem = new Coro::Semaphore 2; - -my $rand = 0; - -sub xrand { - $rand = ($rand * 121 + 2121) % 212121; - $rand / 212120 -} +{ + my $sem = new Coro::Semaphore 2; -my $counter; + my $rand = 0; -$_->join for - map { - async { - my $current = $Coro::current; - for (1..100) { - cede if 0.2 > xrand; - Coro::async_pool { $current->ready } if 0.2 > xrand; - $counter += $sem->count; - my $guard = $sem->guard; - cede; cede; cede; cede; + sub xrand { + $rand = ($rand * 121 + 2121) % 212121; + $rand / 212120 + } + + my $counter; + + $_->join for + map { + async { + my $current = $Coro::current; + for (1..100) { + cede if 0.2 > xrand; + Coro::async_pool { $current->ready } if 0.2 > xrand; + $counter += $sem->count; + my $guard = $sem->guard; + cede; cede; cede; cede; + } } - } - } 1..15 -; + } 1..15 + ; -print $counter == 750 ? "" : "not ", "ok 1 # $counter\n"; + print $counter == 998 ? "" : "not ", "ok 1 # $counter\n"; +} { my $sem = new Coro::Semaphore 0;