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