Fixed race condtions and deadlocks in interaction with
[p5sagit/p5-mst-13.2.git] / ext / threads / shared / t / cond.t
1 BEGIN {
2     chdir 't' if -d 't';
3     push @INC ,'../lib';
4     require Config; import Config;
5     unless ($Config{'useithreads'}) {
6         print "1..0 # Skip: no threads\n";
7         exit 0;
8     }
9 }
10 print "1..5\n";
11 use strict;
12
13
14 use threads;
15
16 use threads::shared;
17
18 my $lock : shared;
19
20 sub foo {
21     lock($lock);
22     print "ok 1\n";
23     sleep 2;
24     print "ok 2\n";
25     cond_wait($lock);
26     print "ok 5\n";
27 }
28
29 sub bar {
30     lock($lock);
31     print "ok 3\n";
32     cond_signal($lock);
33     print "ok 4\n";
34 }
35
36 my $tr  = threads->create(\&foo);
37 my $tr2 = threads->create(\&bar);
38 $tr->join();
39 $tr2->join();
40