4 require Config; import Config;
5 unless ($Config{'useithreads'}) {
6 print "1..0 # Skip: no useithreads\n";
11 use ExtUtils::testlib;
13 BEGIN { print "1..12\n" };
19 use Devel::Peek qw(Dump);
24 # You have to do it this way or VMS will get confused.
25 print $ok ? "ok $test_id - $name\n" : "not ok $test_id - $name\n";
27 printf "# Failed test at line %d\n", (caller)[2] unless $ok;
33 ok(1, "# Skipped: @_");
40 my $retval = threads->create(sub { return ("hi") })->join();
41 ok($retval eq 'hi', "Check basic returnvalue");
44 my ($thread) = threads->create(sub { return (1,2,3) });
45 my @retval = $thread->join();
46 ok($retval[0] == 1 && $retval[1] == 2 && $retval[2] == 3,'');
49 my $retval = threads->create(sub { return [1] })->join();
50 ok($retval->[0] == 1,"Check that a array ref works",);
53 my $retval = threads->create(sub { return { foo => "bar" }})->join();
54 ok($retval->{foo} eq 'bar',"Check that hash refs work");
57 my $retval = threads->create( sub {
58 open(my $fh, "+>threadtest") || die $!;
62 ok(ref($retval) eq 'GLOB', "Check that we can return FH $retval");
63 print $retval "test2\n";
65 # ok(<$retval> eq "test\n");
71 my $retval = threads->create(sub { return $_[0]}, \$test)->join();
72 ok($$retval eq 'hi','');
77 my $retval = threads->create(sub { return $_[0]}, \$test)->join();
78 ok($$retval eq 'hi','');
80 ok($$retval eq 'foo','');
89 return $foo{bar} = \$foo;
94 # We parse ps output so this is OS-dependent.
95 if ($^O =~ /^(linux|dec_osf)$/) {
96 # First modify $0 in a subthread.
97 print "# mainthread: \$0 = $0\n";
99 print "# subthread: \$0 = $0\n";
101 print "# subthread: \$0 = $0\n" } )->join;
102 print "# mainthread: \$0 = $0\n";
103 print "# pid = $$\n";
104 if (open PS, "ps -f |") { # Note: must work in (all) systems.
105 my ($sawpid, $sawexe);
111 if (/\sfoobar\s*$/) { # Linux 2.2 leaves extra trailing spaces.
119 ok($sawpid && $sawexe, 'altering $0 is effective');
121 skip("\$0 check: did not see pid $$ in 'ps -f |'");
124 skip("\$0 check: opening 'ps -f |' failed: $!");
127 skip("\$0 check: only on Linux");
131 my $t = threads->new(sub {});
133 my $x = threads->new(sub {});
139 $ok++ if($@ =~/Thread already joined/);
140 ok($ok, "Double join works");