6 unless ($Config{useithreads}) {
7 print "1..0 # SKIP your perl does not support ithreads\n";
13 unless (eval { require threads }) {
14 print "1..0 # SKIP threads.pm not installed\n";
20 package Test::Scope::Guard;
21 sub new { my ($class, $code) = @_; bless [$code], $class; }
22 sub DESTROY { my $self = shift; $self->[0]->() }
25 package Test::Thread::Clone;
27 sub new { my ($class, $code) = @_; push @code, $code; bless [$code], $class; }
28 sub CLONE { $_->() for @code }
36 our $had_error :shared;
37 END { $? = $had_error||0 }
40 $had_error++, print "not " if !$_[0];
42 print " - $_[1]" if defined $_[1];
46 # load it before spawning a thread, that's the whole point
47 use Devel::GlobalDestruction::XS;
49 our $cloner = Test::Thread::Clone->new(sub {
50 ok( ! Devel::GlobalDestruction::XS::in_global_destruction(), "CLONE is not GD" );
51 my $guard = Test::Scope::Guard->new(sub {
52 ok( ! Devel::GlobalDestruction::XS::in_global_destruction(), "DESTROY during CLONE is not GD");
55 our $global = Test::Scope::Guard->new(sub {
56 ok( Devel::GlobalDestruction::XS::in_global_destruction(), "Final cleanup object destruction properly in GD in " . (threads->tid ? 'thread' : 'main program') );
60 # just die so we don't need to deal with testcount skew
61 unless ( ($_[0]||'') eq 'arg' ) {
63 die "Argument passing failed!";
65 # nothing really to do in here
69 threads->create('do_test', 'arg')->join