Commit | Line | Data |
6794f985 |
1 | |
2 | BEGIN { |
3 | chdir 't' if -d 't'; |
974ec8aa |
4 | push @INC, '../lib'; |
6794f985 |
5 | require Config; import Config; |
6 | unless ($Config{'useithreads'}) { |
7 | print "1..0 # Skip: no useithreads\n"; |
8 | exit 0; |
9 | } |
10 | } |
11 | |
12 | use ExtUtils::testlib; |
13 | |
14 | use strict; |
15 | |
16 | |
17 | BEGIN { $| = 1; print "1..8\n" }; |
74bf223e |
18 | use threads; |
6794f985 |
19 | |
20 | |
21 | |
74bf223e |
22 | print "ok 1\n"; |
6794f985 |
23 | |
24 | |
74bf223e |
25 | ######################### |
26 | sub ok { |
27 | my ($id, $ok, $name) = @_; |
6794f985 |
28 | |
74bf223e |
29 | # You have to do it this way or VMS will get confused. |
30 | print $ok ? "ok $id - $name\n" : "not ok $id - $name\n"; |
6794f985 |
31 | |
74bf223e |
32 | printf "# Failed test at line %d\n", (caller)[2] unless $ok; |
6794f985 |
33 | |
74bf223e |
34 | return $ok; |
35 | } |
6794f985 |
36 | |
a31a65c0 |
37 | ok(2, scalar @{[threads->list]} == 0,''); |
6794f985 |
38 | |
39 | |
6794f985 |
40 | |
74bf223e |
41 | threads->create(sub {})->join(); |
a31a65c0 |
42 | ok(3, scalar @{[threads->list]} == 0,''); |
74bf223e |
43 | |
44 | my $thread = threads->create(sub {}); |
a31a65c0 |
45 | ok(4, scalar @{[threads->list]} == 1,''); |
74bf223e |
46 | $thread->join(); |
a31a65c0 |
47 | ok(5, scalar @{[threads->list]} == 0,''); |
74bf223e |
48 | |
a31a65c0 |
49 | $thread = threads->create(sub { ok(6, threads->self == (threads->list)[0],'')}); |
da32f63e |
50 | threads->yield; # help out non-preemptive thread implementations |
74bf223e |
51 | sleep 1; |
a31a65c0 |
52 | ok(7, $thread == (threads->list)[0],''); |
74bf223e |
53 | $thread->join(); |
a31a65c0 |
54 | ok(8, scalar @{[threads->list]} == 0,''); |