5 require Config; import Config;
6 unless ($Config{'useithreads'}) {
7 print "1..0 # Skip: no useithreads\n";
12 use ExtUtils::testlib;
14 BEGIN { print "1..11\n" };
20 use Devel::Peek qw(Dump);
25 # You have to do it this way or VMS will get confused.
26 print $ok ? "ok $test_id - $name\n" : "not ok $test_id - $name\n";
28 printf "# Failed test at line %d\n", (caller)[2] unless $ok;
37 my $retval = threads->create(sub { return ("hi") })->join();
38 ok($retval eq 'hi', "Check basic returnvalue");
41 my ($thread) = threads->create(sub { return (1,2,3) });
42 my @retval = $thread->join();
43 ok($retval[0] == 1 && $retval[1] == 2 && $retval[2] == 3);
46 my $retval = threads->create(sub { return [1] })->join();
47 ok($retval->[0] == 1,"Check that a array ref works");
50 my $retval = threads->create(sub { return { foo => "bar" }})->join();
51 ok($retval->{foo} eq 'bar',"Check that hash refs work");
54 my $retval = threads->create( sub {
55 open(my $fh, "+>threadtest") || die $!;
59 ok(ref($retval) eq 'GLOB', "Check that we can return FH $retval");
60 print $retval "test2\n";
62 # ok(<$retval> eq "test\n");
68 my $retval = threads->create(sub { return $_[0]}, \$test)->join();
74 my $retval = threads->create(sub { return $_[0]}, \$test)->join();
77 ok($$retval eq 'foo');
86 return $foo{bar} = \$foo;
91 if ($^O eq 'linux') { # We parse ps output so this is OS-dependent.
93 # First modify $0 in a subthread.
94 print "# 1a: \$0 = $0\n";
95 join( threads->new( sub {
96 print "# 2a: \$0 = $0\n";
98 print "# 2b: \$0 = $0\n" } ) );
99 print "# 1b: \$0 = $0\n";
100 if (open PS, "ps -f |") {
104 if (/^\S+\s+$$\s.+\sfoobar\s*$/) {
110 ok($ok, 'altering $0 is effective');
112 skip("\$0 check: opening 'ps -f |' failed: $!");
115 skip("\$0 check: only on Linux");