All the authors of these modules have now been contacted;
[p5sagit/p5-mst-13.2.git] / ext / Thread / lock.tx
CommitLineData
0fcb073c 1BEGIN {
2 eval { require Config; import Config };
3 if ($@) {
4 print "1..0 # Skip: no Config\n";
5 exit(0);
6 }
0fcb073c 7}
8
734689b1 9use Thread;
10
11$level = 0;
12
13sub worker
14{
15 my $num = shift;
16 my $i;
17 print "thread $num starting\n";
18 for ($i = 1; $i <= 20; $i++) {
19 print "thread $num iteration $i\n";
20 select(undef, undef, undef, rand(10)/100);
21 {
783070da 22 lock($lock);
734689b1 23 warn "thread $num saw non-zero level = $level\n" if $level;
24 $level++;
25 print "thread $num has lock\n";
26 select(undef, undef, undef, rand(10)/100);
27 $level--;
28 }
29 print "thread $num released lock\n";
30 }
31}
32
33for ($t = 1; $t <= 5; $t++) {
34 new Thread \&worker, $t;
35}