1
2BEGIN {
3    chdir 't' if -d 't';
4    push @INC, '../lib';
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" };
18use threads;
19
20
21
22print "ok 1\n";
23
24
25#########################
26sub ok {
27    my ($id, $ok, $name) = @_;
28
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";
31
32    printf "# Failed test at line %d\n", (caller)[2] unless $ok;
33
34    return $ok;
35}
36
37ok(2, scalar @{[threads->list]} == 0,'');
38
39
40
41threads->create(sub {})->join();
42ok(3, scalar @{[threads->list]} == 0,'');
43
44my $thread = threads->create(sub {});
45ok(4, scalar @{[threads->list]} == 1,'');
46$thread->join();
47ok(5, scalar @{[threads->list]} == 0,'');
48
49$thread = threads->create(sub { ok(6, threads->self == (threads->list)[0],'')});
50threads->yield; # help out non-preemptive thread implementations
51sleep 1;
52ok(7, $thread == (threads->list)[0],'');
53$thread->join();
54ok(8, scalar @{[threads->list]} == 0,'');
55