This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Rewrote programmer-level condition variables from scratch. Added
[perl5.git] / lock.t
CommitLineData
734689b1
MB
1use Thread;
2
3$level = 0;
4
5sub worker
6{
7 my $num = shift;
8 my $i;
9 print "thread $num starting\n";
10 for ($i = 1; $i <= 20; $i++) {
11 print "thread $num iteration $i\n";
12 select(undef, undef, undef, rand(10)/100);
13 {
14 reset($lock);
15 warn "thread $num saw non-zero level = $level\n" if $level;
16 $level++;
17 print "thread $num has lock\n";
18 select(undef, undef, undef, rand(10)/100);
19 $level--;
20 }
21 print "thread $num released lock\n";
22 }
23}
24
25for ($t = 1; $t <= 5; $t++) {
26 new Thread \&worker, $t;
27}