Commit | Line | Data |
734689b1 |
1 | use Thread; |
2 | |
3 | $level = 0; |
4 | |
5 | sub 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 | { |
783070da |
14 | lock($lock); |
734689b1 |
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 | |
25 | for ($t = 1; $t <= 5; $t++) { |
26 | new Thread \&worker, $t; |
27 | } |