blob: f0a51efe1f7e1a80027ee595b8fcbd933cbb6bdd (
plain)
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
|
use Thread;
$| = 1;
if (@ARGV) {
srand($ARGV[0]);
} else {
my $seed = $$ ^ $^T;
print "Randomising to $seed\n";
srand($seed);
}
sub whoami {
my ($depth, $a, $b, $c) = @_;
my $i;
print "whoami ($depth): $a $b $c\n";
sleep 1;
whoami($depth - 1, $a, $b, $c) if $depth > 0;
}
sub start_foo {
my $r = 3 + int(10 * rand);
print "start_foo: r is $r\n";
whoami($r, "start_foo", "foo1", "foo2");
print "start_foo: finished\n";
}
sub start_bar {
my $r = 3 + int(10 * rand);
print "start_bar: r is $r\n";
whoami($r, "start_bar", "bar1", "bar2");
print "start_bar: finished\n";
}
$foo = new Thread \&start_foo;
$bar = new Thread \&start_bar;
print "main: exiting\n";
|