Commit | Line | Data |
0fcb073c |
1 | BEGIN { |
2 | eval { require Config; import Config }; |
3 | if ($@) { |
4 | print "1..0 # Skip: no Config\n"; |
5 | exit(0); |
0fcb073c |
6 | } |
7 | } |
8 | |
d9bb3666 |
9 | use Thread; |
10 | |
11 | $level = 0; |
12 | |
0655b981 |
13 | sub single_file : locked { |
d9bb3666 |
14 | my $arg = shift; |
15 | $level++; |
16 | print "Level $level for $arg\n"; |
17 | print "(something is wrong)\n" if $level < 0 || $level > 1; |
18 | sleep 1; |
19 | $level--; |
20 | print "Back to level $level\n"; |
21 | } |
22 | |
23 | sub start_bar { |
24 | my $i; |
25 | print "start bar\n"; |
26 | for $i (1..3) { |
27 | print "bar $i\n"; |
28 | single_file("bar $i"); |
29 | sleep 1 if rand > 0.5; |
30 | } |
31 | print "end bar\n"; |
32 | return 1; |
33 | } |
34 | |
35 | sub start_foo { |
36 | my $i; |
37 | print "start foo\n"; |
38 | for $i (1..3) { |
39 | print "foo $i\n"; |
40 | single_file("foo $i"); |
41 | sleep 1 if rand > 0.5; |
42 | } |
43 | print "end foo\n"; |
44 | return 1; |
45 | } |
46 | |
47 | sub start_baz { |
48 | my $i; |
49 | print "start baz\n"; |
50 | for $i (1..3) { |
51 | print "baz $i\n"; |
52 | single_file("baz $i"); |
53 | sleep 1 if rand > 0.5; |
54 | } |
55 | print "end baz\n"; |
56 | return 1; |
57 | } |
58 | |
59 | $| = 1; |
60 | srand($$^$^T); |
d9bb3666 |
61 | |
62 | $foo = new Thread \&start_foo; |
63 | $bar = new Thread \&start_bar; |
64 | $baz = new Thread \&start_baz; |
65 | $foo->join(); |
66 | $bar->join(); |
67 | $baz->join(); |
68 | print "main: threads finished, exiting\n"; |