1 | $|=1; |
1 | $|=1; |
2 | print "1..2\n"; |
2 | print "1..6\n"; |
3 | |
3 | |
4 | use Coro; |
4 | use Coro; |
5 | use Coro::Semaphore; |
5 | use Coro::Semaphore; |
6 | |
6 | |
7 | { |
7 | { |
… | |
… | |
32 | ; |
32 | ; |
33 | |
33 | |
34 | print $counter == 998 ? "" : "not ", "ok 1 # $counter\n"; |
34 | print $counter == 998 ? "" : "not ", "ok 1 # $counter\n"; |
35 | } |
35 | } |
36 | |
36 | |
|
|
37 | # check terminate |
37 | { |
38 | { |
38 | my $sem = new Coro::Semaphore 0; |
39 | my $sem = new Coro::Semaphore 0; |
39 | |
40 | |
40 | $as1 = async { |
41 | $as1 = async { |
41 | my $g = $sem->guard; |
42 | my $g = $sem->guard; |
… | |
… | |
53 | $as1->cancel; # destroy as1 before it could ->guard |
54 | $as1->cancel; # destroy as1 before it could ->guard |
54 | $as1->join; |
55 | $as1->join; |
55 | $as2->join; |
56 | $as2->join; |
56 | } |
57 | } |
57 | |
58 | |
|
|
59 | # check throw |
|
|
60 | { |
|
|
61 | my $sem = new Coro::Semaphore 0; |
58 | |
62 | |
|
|
63 | $as1 = async { |
|
|
64 | my $g = eval { |
|
|
65 | $sem->guard; |
|
|
66 | }; |
|
|
67 | print $@ ? "" : "not ", "ok 3\n"; |
|
|
68 | }; |
|
|
69 | |
|
|
70 | $as2 = async { |
|
|
71 | my $g = $sem->guard; |
|
|
72 | print "ok 4\n"; |
|
|
73 | }; |
|
|
74 | |
|
|
75 | cede; |
|
|
76 | |
|
|
77 | $sem->up; # wake up as1 |
|
|
78 | $as1->throw (1); # destroy as1 before it could ->guard |
|
|
79 | $as1->join; |
|
|
80 | $as2->join; |
|
|
81 | } |
|
|
82 | |
|
|
83 | # check wait |
|
|
84 | { |
|
|
85 | my $sem = new Coro::Semaphore 0; |
|
|
86 | |
|
|
87 | $as1 = async { |
|
|
88 | $sem->wait; |
|
|
89 | print "ok 5\n"; |
|
|
90 | }; |
|
|
91 | |
|
|
92 | $as2 = async { |
|
|
93 | my $g = $sem->guard; |
|
|
94 | print "ok 6\n"; |
|
|
95 | }; |
|
|
96 | |
|
|
97 | cede; |
|
|
98 | |
|
|
99 | $sem->up; # wake up as1 |
|
|
100 | $as1->join; |
|
|
101 | $as2->join; |
|
|
102 | } |
|
|
103 | |
|
|
104 | |