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