Make #11082 more OS/2-specific.
[p5sagit/p5-mst-13.2.git] / ext / Thread / lock.tx
1 BEGIN {
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
13 use Thread;
14
15 $level = 0;
16
17 sub 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         {
26             lock($lock);
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
37 for ($t = 1; $t <= 5; $t++) {
38     new Thread \&worker, $t;
39 }