summaryrefslogtreecommitdiff
path: root/ext/threads/shared/t/cond.t
blob: 28de99c66c84dddde75443d36c7d57cdff6d0a0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use warnings;

BEGIN {
    chdir 't' if -d 't';
    push @INC ,'../lib';
    require Config; import Config;
    unless ($Config{'useithreads'}) {
        print "1..0 # Skip: no threads\n";
        exit 0;
    }
}
$|++;
print "1..5\n";
use strict;


use threads;

use threads::shared;

my $lock : shared;

sub foo {
    lock($lock);
    print "ok 1\n";
    my $tr2 = threads->create(\&bar);
    cond_wait($lock);
    $tr2->join();
    print "ok 5\n";
}

sub bar {
    print "ok 2\n";
    lock($lock);
    print "ok 3\n";
    cond_signal($lock);
    print "ok 4\n";
}

my $tr  = threads->create(\&foo);
$tr->join();