Commit | Line | Data |
d9bb3666 |
1 | use Thread; |
2 | |
17f28c40 |
3 | sub counter { |
4 | $count = 10; |
5 | while ($count--) { |
6 | sleep 1; |
7 | print "ping $count\n"; |
8 | } |
9 | } |
10 | |
d9bb3666 |
11 | sub reader { |
12 | my $line; |
13 | while ($line = <STDIN>) { |
14 | print "reader: $line"; |
15 | } |
16 | print "End of input in reader\n"; |
17 | return 0; |
18 | } |
19 | |
609f3ea9 |
20 | print <<'EOT'; |
21 | This test starts up a thread to read and echo whatever is typed on |
22 | the keyboard/stdin, line by line, while the main thread counts down |
23 | to zero. The test stays running until both the main thread has |
24 | finished counting down and the I/O thread has seen end-of-file on |
25 | the terminal/stdin. |
26 | EOT |
27 | |
17f28c40 |
28 | $r = new Thread \&counter; |
29 | |
30 | &reader; |
31 | |
32 | __END__ |
33 | |
34 | |
609f3ea9 |
35 | $count = 10; |
d9bb3666 |
36 | while ($count--) { |
37 | sleep 1; |
38 | print "ping $count\n"; |
39 | } |