This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Cleanup in Hash::Util::FieldHash
[perl5.git] / ext / Thread / sync2.tx
CommitLineData
0fcb073c
JH
1BEGIN {
2 eval { require Config; import Config };
3 if ($@) {
4 print "1..0 # Skip: no Config\n";
5 exit(0);
6 }
0fcb073c
JH
7}
8
d9bb3666
MB
9use Thread;
10
11$global = undef;
12
0655b981 13sub single_file : locked {
d9bb3666
MB
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
MB
23 }
24 print "]";
25 $global = undef;
26}
27
28sub 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
MB
35 }
36 }
37}
38
39sub start_b {
40 my ($i, $j);
609f3ea9
MB
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
MB
46 }
47 }
48}
49
50sub start_c {
51 my ($i, $j);
609f3ea9
MB
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
MB
57 }
58 }
59}
60
61$| = 1;
62srand($$^$^T);
d9bb3666 63
609f3ea9
MB
64print <<'EOT';
65Each pair of square brackets [...] should contain a repeated sequence of
66a unique upper case letter. Lower case letters may appear randomly both
67in and out of the brackets.
68EOT
d9bb3666
MB
69$foo = new Thread \&start_a;
70$bar = new Thread \&start_b;
71$baz = new Thread \&start_c;
72print "\nmain: joining...\n";
609f3ea9
MB
73#$foo->join;
74#$bar->join;
75#$baz->join;
76print "\ndone\n";