Commit | Line | Data |
---|---|---|
89661126 | 1 | BEGIN { |
2 | chdir 't' if -d 't'; | |
b5135157 | 3 | push @INC ,'../lib'; |
89661126 | 4 | require Config; import Config; |
5 | unless ($Config{'useithreads'}) { | |
6 | print "1..0 # Skip: no threads\n"; | |
7 | exit 0; | |
8 | } | |
9 | } | |
cd055192 | 10 | $|++; |
b5135157 | 11 | print "1..5\n"; |
89661126 | 12 | use strict; |
13 | ||
b5135157 | 14 | |
89661126 | 15 | use threads; |
16 | ||
17 | use threads::shared; | |
18 | ||
19 | my $lock : shared; | |
20 | ||
21 | sub foo { | |
22 | lock($lock); | |
b5135157 | 23 | print "ok 1\n"; |
24 | sleep 2; | |
25 | print "ok 2\n"; | |
89661126 | 26 | cond_wait($lock); |
b5135157 | 27 | print "ok 5\n"; |
89661126 | 28 | } |
29 | ||
30 | sub bar { | |
31 | lock($lock); | |
b5135157 | 32 | print "ok 3\n"; |
89661126 | 33 | cond_signal($lock); |
b5135157 | 34 | print "ok 4\n"; |
89661126 | 35 | } |
36 | ||
b5135157 | 37 | my $tr = threads->create(\&foo); |
89661126 | 38 | my $tr2 = threads->create(\&bar); |
b5135157 | 39 | $tr->join(); |
40 | $tr2->join(); | |
89661126 | 41 |