Encode::Tcl.pm for iso-2022-(?:jp-[12]|cn)
[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 }
7 if ($Config{extensions} !~ /\bThread\b/) {
8 print "1..0 # Skip: no use5005threads\n";
9 exit(0);
10 }
11}
12
734689b1 13use Thread;
14
15$level = 0;
16
17sub worker
18{
19 my $num = shift;
20 my $i;
21 print "thread $num starting\n";
22 for ($i = 1; $i <= 20; $i++) {
23 print "thread $num iteration $i\n";
24 select(undef, undef, undef, rand(10)/100);
25 {
783070da 26 lock($lock);
734689b1 27 warn "thread $num saw non-zero level = $level\n" if $level;
28 $level++;
29 print "thread $num has lock\n";
30 select(undef, undef, undef, rand(10)/100);
31 $level--;
32 }
33 print "thread $num released lock\n";
34 }
35}
36
37for ($t = 1; $t <= 5; $t++) {
38 new Thread \&worker, $t;
39}