5 if ($ENV{'PERL_CORE'}){
7 unshift @INC, '../lib';
10 unless ($Config{'useithreads'}) {
11 print "1..0 # Skip: no useithreads\n";
16 use ExtUtils::testlib;
18 BEGIN { print "1..14\n" };
24 use Devel::Peek qw(Dump);
29 lock $test_id; # make print and increment atomic
31 # You have to do it this way or VMS will get confused.
32 print $ok ? "ok $test_id - $name\n" : "not ok $test_id - $name\n";
34 printf "# Failed test at line %d\n", (caller)[2] unless $ok;
40 ok(1, "# Skipped: @_");
47 my $retval = threads->create(sub { return ("hi") })->join();
48 ok($retval eq 'hi', "Check basic returnvalue");
51 my ($thread) = threads->create(sub { return (1,2,3) });
52 my @retval = $thread->join();
53 ok($retval[0] == 1 && $retval[1] == 2 && $retval[2] == 3,'');
56 my $retval = threads->create(sub { return [1] })->join();
57 ok($retval->[0] == 1,"Check that a array ref works",);
60 my $retval = threads->create(sub { return { foo => "bar" }})->join();
61 ok($retval->{foo} eq 'bar',"Check that hash refs work");
64 my $retval = threads->create( sub {
65 open(my $fh, "+>threadtest") || die $!;
69 ok(ref($retval) eq 'GLOB', "Check that we can return FH $retval");
70 print $retval "test2\n";
72 # ok(<$retval> eq "test\n");
78 my $retval = threads->create(sub { return $_[0]}, \$test)->join();
79 ok($$retval eq 'hi','');
84 my $retval = threads->create(sub { return $_[0]}, \$test)->join();
85 ok($$retval eq 'hi','');
87 ok($$retval eq 'foo','');
96 return $foo{bar} = \$foo;
101 # We parse ps output so this is OS-dependent.
102 if ($^O eq 'linux') {
103 # First modify $0 in a subthread.
104 print "# mainthread: \$0 = $0\n";
106 print "# subthread: \$0 = $0\n";
108 print "# subthread: \$0 = $0\n" } )->join;
109 print "# mainthread: \$0 = $0\n";
110 print "# pid = $$\n";
111 if (open PS, "ps -f |") { # Note: must work in (all) systems.
112 my ($sawpid, $sawexe);
118 if (/\sfoobar\s*$/) { # Linux 2.2 leaves extra trailing spaces.
126 ok($sawpid && $sawexe, 'altering $0 is effective');
128 skip("\$0 check: did not see pid $$ in 'ps -f |'");
131 skip("\$0 check: opening 'ps -f |' failed: $!");
134 skip("\$0 check: only on Linux");
138 my $t = threads->new(sub {});
140 my $x = threads->new(sub {});
146 $ok++ if($@ =~/Thread already joined/);
147 ok($ok, "Double join works");
151 # The "use IO::File" is not actually used for anything; its only
152 # purpose is to incite a lot of calls to newCONSTSUB. See the p5p
153 # archives for the thread "maint@20974 or before broke mp2 ithreads test".
155 # this coredumped between #20930 and #21000
156 $_->join for map threads->new(sub{ok($_, "stress newCONSTSUB")}), 1..2;