source: trunk/essentials/dev-lang/perl/ext/Thread/lock.tx

Last change on this file was 3181, checked in by bird, 18 years ago

perl 5.8.8

File size: 655 bytes
Line 
1BEGIN {
2 eval { require Config; import Config };
3 if ($@) {
4 print "1..0 # Skip: no Config\n";
5 exit(0);
6 }
7}
8
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 {
22 lock($lock);
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}
Note: See TracBrowser for help on using the repository browser.