This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
First steps of making builds outside the source
[perl5.git] / ext / Thread / unsync.t
1 use Thread;
2
3 $| = 1;
4
5 if (@ARGV) {
6     srand($ARGV[0]);
7 } else {
8     my $seed = $$ ^ $^T;
9     print "Randomising to $seed\n";
10     srand($seed);
11 }
12
13 sub whoami {
14     my ($depth, $a, $b, $c) = @_;
15     my $i;
16     print "whoami ($depth): $a $b $c\n";
17     sleep 1;
18     whoami($depth - 1, $a, $b, $c) if $depth > 0;
19 }
20
21 sub start_foo {
22     my $r = 3 + int(10 * rand);
23     print "start_foo: r is $r\n";
24     whoami($r, "start_foo", "foo1", "foo2");
25     print "start_foo: finished\n";
26 }
27
28 sub start_bar {
29     my $r = 3 + int(10 * rand);
30     print "start_bar: r is $r\n";
31     whoami($r, "start_bar", "bar1", "bar2");
32     print "start_bar: finished\n";
33 }
34
35 $foo = new Thread \&start_foo;
36 $bar = new Thread \&start_bar;
37 print "main: exiting\n";