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); |
6 | } |
0fcb073c |
7 | } |
8 | |
d9bb3666 |
9 | use Thread; |
10 | |
11 | $global = undef; |
12 | |
0655b981 |
13 | sub single_file : locked { |
d9bb3666 |
14 | my $who = shift; |
15 | my $i; |
16 | |
17 | print "Uh oh: $who entered while locked by $global\n" if $global; |
18 | $global = $who; |
19 | print "["; |
609f3ea9 |
20 | for ($i = 0; $i < int(10 * rand); $i++) { |
d9bb3666 |
21 | print $who; |
609f3ea9 |
22 | select(undef, undef, undef, 0.1); |
d9bb3666 |
23 | } |
24 | print "]"; |
25 | $global = undef; |
26 | } |
27 | |
28 | sub start_a { |
29 | my ($i, $j); |
609f3ea9 |
30 | for ($j = 0; $j < 10; $j++) { |
d9bb3666 |
31 | single_file("A"); |
609f3ea9 |
32 | for ($i = 0; $i < int(10 * rand); $i++) { |
d9bb3666 |
33 | print "a"; |
609f3ea9 |
34 | select(undef, undef, undef, 0.1); |
d9bb3666 |
35 | } |
36 | } |
37 | } |
38 | |
39 | sub start_b { |
40 | my ($i, $j); |
609f3ea9 |
41 | for ($j = 0; $j < 10; $j++) { |
42 | single_file("B"); |
43 | for ($i = 0; $i < int(10 * rand); $i++) { |
d9bb3666 |
44 | print "b"; |
609f3ea9 |
45 | select(undef, undef, undef, 0.1); |
d9bb3666 |
46 | } |
47 | } |
48 | } |
49 | |
50 | sub start_c { |
51 | my ($i, $j); |
609f3ea9 |
52 | for ($j = 0; $j < 10; $j++) { |
53 | single_file("C"); |
54 | for ($i = 0; $i < int(10 * rand); $i++) { |
55 | print "c"; |
56 | select(undef, undef, undef, 0.1); |
d9bb3666 |
57 | } |
58 | } |
59 | } |
60 | |
61 | $| = 1; |
62 | srand($$^$^T); |
d9bb3666 |
63 | |
609f3ea9 |
64 | print <<'EOT'; |
65 | Each pair of square brackets [...] should contain a repeated sequence of |
66 | a unique upper case letter. Lower case letters may appear randomly both |
67 | in and out of the brackets. |
68 | EOT |
d9bb3666 |
69 | $foo = new Thread \&start_a; |
70 | $bar = new Thread \&start_b; |
71 | $baz = new Thread \&start_c; |
72 | print "\nmain: joining...\n"; |
609f3ea9 |
73 | #$foo->join; |
74 | #$bar->join; |
75 | #$baz->join; |
76 | print "\ndone\n"; |