source: trunk/essentials/dev-lang/perl/ext/Thread/unsync.tx

Last change on this file was 3181, checked in by bird, 18 years ago

perl 5.8.8

File size: 849 bytes
Line 
1BEGIN {
2 eval { require Config; import Config };
3 if ($@) {
4 print "1..0 # Skip: no Config\n";
5 exit(0);
6 }
7}
8
9use Thread;
10
11$| = 1;
12
13if (@ARGV) {
14 srand($ARGV[0]);
15} else {
16 my $seed = $$ ^ $^T;
17 print "Randomising to $seed\n";
18 srand($seed);
19}
20
21sub whoami {
22 my ($depth, $a, $b, $c) = @_;
23 my $i;
24 print "whoami ($depth): $a $b $c\n";
25 sleep 1;
26 whoami($depth - 1, $a, $b, $c) if $depth > 0;
27}
28
29sub start_foo {
30 my $r = 3 + int(10 * rand);
31 print "start_foo: r is $r\n";
32 whoami($r, "start_foo", "foo1", "foo2");
33 print "start_foo: finished\n";
34}
35
36sub start_bar {
37 my $r = 3 + int(10 * rand);
38 print "start_bar: r is $r\n";
39 whoami($r, "start_bar", "bar1", "bar2");
40 print "start_bar: finished\n";
41}
42
43$foo = new Thread \&start_foo;
44$bar = new Thread \&start_bar;
45print "main: exiting\n";
Note: See TracBrowser for help on using the repository browser.