ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/staticperl/perl/ext/Thread/lock.tx
Revision: 1.1
Committed: Thu Jun 30 14:27:05 2005 UTC (21 years, 3 months ago) by root
Branch: MAIN
CVS Tags: PERL-5-8-7, HEAD
Branch point for: PERL
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 BEGIN {
2     eval { require Config; import Config };
3     if ($@) {
4     print "1..0 # Skip: no Config\n";
5     exit(0);
6     }
7     }
8    
9     use Thread;
10    
11     $level = 0;
12    
13     sub 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    
33     for ($t = 1; $t <= 5; $t++) {
34     new Thread \&worker, $t;
35     }