Commit | Line | Data |
d55594ae |
1 | #!perl |
2 | |
3 | BEGIN { |
4 | chdir 't' if -d 't'; |
5 | @INC = '../lib'; |
6 | require Config; import Config; |
7 | if ($Config{'ccflags'} !~ /-DUSE_THREADS\b/) { |
8 | print "1..0\n"; |
9 | exit 0; |
10 | } |
11 | } |
12 | $| = 1; |
13 | print "1..9\n"; |
14 | use Thread; |
15 | print "ok 1\n"; |
16 | |
17 | sub content |
18 | { |
19 | print shift; |
20 | return shift; |
21 | } |
22 | |
23 | # create a thread passing args and immedaietly wait for it. |
24 | my $t = new Thread \&content,("ok 2\n","ok 3\n"); |
25 | print $t->join; |
26 | |
27 | # check that lock works ... |
28 | {lock $foo; |
29 | $t = new Thread sub { lock $foo; print "ok 5\n" }; |
30 | print "ok 4\n"; |
31 | } |
32 | $t->join; |
33 | |
34 | sub islocked |
35 | { |
36 | use attrs 'locked'; |
37 | my $val = shift; |
38 | my $ret; |
39 | if (@_) |
40 | { |
41 | $ret = new Thread \&islocked,shift; |
42 | sleep 2; |
43 | } |
44 | print $val; |
45 | } |
46 | |
47 | $t = islocked("ok 6\n","ok 7\n"); |
48 | join $t; |
49 | |
50 | # test that sleep lets other thread run |
51 | $t = new Thread \&islocked,"ok 8\n"; |
52 | sleep 2; |
53 | print "ok 9"; |
54 | join $t; |