Initial import from FreeBSD RELENG_4:
[games.git] / contrib / perl5 / ext / Thread / io.t
1 use Thread;
2
3 sub counter {
4 $count = 10;
5 while ($count--) {
6     sleep 1;
7     print "ping $count\n";
8 }
9 }
10
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
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
28 $r = new Thread \&counter;
29
30 &reader;
31
32 __END__
33
34
35 $count = 10;
36 while ($count--) {
37     sleep 1;
38     print "ping $count\n";
39 }