ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/t/15_semaphore.t
(Generate patch)

Comparing Coro/t/15_semaphore.t (file contents):
Revision 1.2 by root, Sun Nov 16 09:43:18 2008 UTC vs.
Revision 1.3 by root, Sun Nov 16 10:33:08 2008 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines