Commit | Line | Data |
0f1612a7 |
1 | use strict; |
2 | use warnings; |
6794f985 |
3 | |
4 | BEGIN { |
0f1612a7 |
5 | if ($ENV{'PERL_CORE'}){ |
6 | chdir 't'; |
7 | unshift @INC, '../lib'; |
8 | } |
9 | use Config; |
fc04eb16 |
10 | if (! $Config{'useithreads'}) { |
11 | print("1..0 # Skip: Perl not compiled with 'useithreads'\n"); |
12 | exit(0); |
6794f985 |
13 | } |
14 | } |
15 | |
16 | use ExtUtils::testlib; |
17 | |
fc04eb16 |
18 | sub ok { |
74bf223e |
19 | my ($id, $ok, $name) = @_; |
6794f985 |
20 | |
74bf223e |
21 | # You have to do it this way or VMS will get confused. |
fc04eb16 |
22 | if ($ok) { |
23 | print("ok $id - $name\n"); |
24 | } else { |
25 | print("not ok $id - $name\n"); |
26 | printf("# Failed test at line %d\n", (caller)[2]); |
27 | } |
6794f985 |
28 | |
fc04eb16 |
29 | return ($ok); |
74bf223e |
30 | } |
6794f985 |
31 | |
fc04eb16 |
32 | BEGIN { |
33 | $| = 1; |
34 | print("1..15\n"); ### Number of tests that will be run ### |
35 | }; |
36 | |
37 | use threads; |
38 | ok(1, 1, 'Loaded'); |
39 | |
f4cc38af |
40 | ### Start of Testing ### |
6794f985 |
41 | |
f4cc38af |
42 | ok(2, scalar @{[threads->list()]} == 0, 'No threads yet'); |
6794f985 |
43 | |
74bf223e |
44 | threads->create(sub {})->join(); |
f4cc38af |
45 | ok(3, scalar @{[threads->list()]} == 0, 'Empty thread list after join'); |
74bf223e |
46 | |
47 | my $thread = threads->create(sub {}); |
f4cc38af |
48 | ok(4, scalar(threads->list()) == 1, 'Non-empty thread list'); |
49 | ok(5, threads->list() == 1, 'Non-empty thread list'); |
74bf223e |
50 | $thread->join(); |
f4cc38af |
51 | ok(6, scalar @{[threads->list()]} == 0, 'Thread list empty again'); |
52 | ok(7, threads->list() == 0, 'Thread list empty again'); |
53 | |
54 | $thread = threads->create(sub { |
55 | ok(8, threads->list() == 1, 'Non-empty thread list in thread'); |
56 | ok(9, threads->self == (threads->list())[0], 'Self in thread list') |
57 | }); |
74bf223e |
58 | |
da32f63e |
59 | threads->yield; # help out non-preemptive thread implementations |
74bf223e |
60 | sleep 1; |
f4cc38af |
61 | |
62 | ok(10, scalar(threads->list()) == 1, 'Thread count 1'); |
63 | ok(11, threads->list() == 1, 'Thread count 1'); |
64 | my $cnt = threads->list(); |
65 | ok(12, $cnt == 1, 'Thread count 1'); |
66 | my ($thr_x) = threads->list(); |
67 | ok(13, $thread == $thr_x, 'Thread in list'); |
74bf223e |
68 | $thread->join(); |
f4cc38af |
69 | ok(14, scalar @{[threads->list()]} == 0, 'Thread list empty'); |
70 | ok(15, threads->list() == 0, 'Thread list empty'); |
71 | |
72 | # EOF |