File: 16_signal.t

package info (click to toggle)
libcoro-perl 6.570-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,144 kB
  • sloc: ansic: 2,560; perl: 2,122; makefile: 14
file content (75 lines) | stat: -rw-r--r-- 1,310 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
$|=1;
print "1..18\n";

no warnings;
use Coro;
use Coro::Signal;

{
   my $sig = new Coro::Signal;

   $as1 = async {
      my $g = $sig->wait;
      print "ok 3\n";
   };    

   $as2 = async {
      my $g = $sig->wait;
      print "ok 4\n";
   };    

   cede; # put 1, 2 in wait q

   $as3 = async {
      my $g = $sig->wait;
      print "ok 2\n";
   };    

   $as4 = async {
      my $g = $sig->wait;
      print "ok 6\n";
   };    

   $as5 = async {
      my $g = $sig->wait;
      print "ok 9\n";
   };    

   $sig->send; # ready 1
   $sig->send; # ready 2
   $sig->send; # remember

   print +(Coro::Semaphore::count $sig) == 1 ? "" : "not ", "ok 1\n";

   cede; # execute 3 (already ready, no contention), 1, 2

   print +(Coro::Semaphore::count $sig) == 0 ? "" : "not ", "ok 5\n";

   $sig->send;
   cede;

   print +(Coro::Semaphore::count $sig) == 0 ? "" : "not ", "ok 7\n";

   $sig->broadcast;
   print +(Coro::Semaphore::count $sig) == 0 ? "" : "not ", "ok 8\n";
   cede;

   $sig->wait (sub { print "ok 12\n" });
   print "ok 10\n";

   print "ok 11\n";

   $sig->send;
   print "ok 13\n";
   cede;

   print "ok 14\n";
   $sig->send;
   print "ok 15\n";

   $sig->wait (sub { print "ok 16\n" });
   print "ok 17\n";

   print +(Coro::Semaphore::count $sig) == 0 ? "" : "not ", "ok 18\n";
}