1 2# test that END blocks are run in the thread that created them and 3# not in any child threads 4 5BEGIN { 6 chdir 't' if -d 't'; 7 push @INC, '../lib'; 8 require Config; import Config; 9 unless ($Config{'useithreads'}) { 10 print "1..0 # Skip: no useithreads\n"; 11 exit 0; 12 } 13 if ($Config{'extensions'} !~ /\bDevel\/Peek\b/) { 14 print "1..0 # Skip: Devel::Peek was not built\n"; 15 exit 0; 16 } 17} 18 19use ExtUtils::testlib; 20use strict; 21BEGIN { print "1..6\n" }; 22use threads; 23use threads::shared; 24 25my $test_id = 1; 26share($test_id); 27use Devel::Peek qw(Dump); 28 29sub ok { 30 my ($ok, $name) = @_; 31 32 # You have to do it this way or VMS will get confused. 33 print $ok ? "ok $test_id - $name\n" : "not ok $test_id - $name\n"; 34 35 printf "# Failed test at line %d\n", (caller)[2] unless $ok; 36 $test_id++; 37 return $ok; 38} 39ok(1,''); 40END { ok(1,"End block run once") } 41threads->create(sub { eval "END { ok(1,'') }"})->join(); 42threads->create(sub { eval "END { ok(1,'') }"})->join(); 43threads->create(\&thread)->join(); 44 45sub thread { 46 eval "END { ok(1,'') }"; 47 threads->create(sub { eval "END { ok(1,'') }"})->join(); 48} 49