1 |
$|=1; |
2 |
print "1..1\n"; |
3 |
|
4 |
use Coro; |
5 |
use Coro::Semaphore; |
6 |
|
7 |
my $sem = new Coro::Semaphore 2; |
8 |
|
9 |
my $rand = 0; |
10 |
|
11 |
sub xrand { |
12 |
$rand = ($rand * 121 + 2121) % 212121; |
13 |
$rand / 212120 |
14 |
} |
15 |
|
16 |
my $counter; |
17 |
|
18 |
$_->join for |
19 |
map { |
20 |
async { |
21 |
my $current = $Coro::current; |
22 |
for (1..100) { |
23 |
cede if 0.2 > xrand; |
24 |
Coro::async_pool { $current->ready } if 0.2 > xrand; |
25 |
$counter += $sem->count; |
26 |
my $guard = $sem->guard; |
27 |
cede; cede; cede; cede; |
28 |
} |
29 |
} |
30 |
} 1..15 |
31 |
; |
32 |
|
33 |
print $counter == 750 ? "" : "not ", "ok 1 # $counter\n" |
34 |
|