Changing the test count is a good idea.
[p5sagit/p5-mst-13.2.git] / ext / threads / t / list.t
CommitLineData
6794f985 1
2BEGIN {
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
12use ExtUtils::testlib;
13
14use strict;
15
16
17BEGIN { $| = 1; print "1..8\n" };
74bf223e 18use threads;
6794f985 19
20
21
74bf223e 22print "ok 1\n";
6794f985 23
24
74bf223e 25#########################
26sub 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 37ok(2, scalar @{[threads->list]} == 0,'');
6794f985 38
39
6794f985 40
74bf223e 41threads->create(sub {})->join();
a31a65c0 42ok(3, scalar @{[threads->list]} == 0,'');
74bf223e 43
44my $thread = threads->create(sub {});
a31a65c0 45ok(4, scalar @{[threads->list]} == 1,'');
74bf223e 46$thread->join();
a31a65c0 47ok(5, scalar @{[threads->list]} == 0,'');
74bf223e 48
a31a65c0 49$thread = threads->create(sub { ok(6, threads->self == (threads->list)[0],'')});
da32f63e 50threads->yield; # help out non-preemptive thread implementations
74bf223e 51sleep 1;
a31a65c0 52ok(7, $thread == (threads->list)[0],'');
74bf223e 53$thread->join();
a31a65c0 54ok(8, scalar @{[threads->list]} == 0,'');