From: Vincent Pit Date: Sat, 27 Sep 2014 23:39:39 +0000 (+0200) Subject: Test that the thread destructors are executed before global destruction X-Git-Tag: v0.06~5 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=5df33e24c91c6ebd942de8ed5eb45dd4c1b24269;p=perl%2Fmodules%2FThread-Cleanup.git Test that the thread destructors are executed before global destruction --- diff --git a/t/10-join.t b/t/10-join.t index ba86a97..a3be761 100644 --- a/t/10-join.t +++ b/t/10-join.t @@ -4,6 +4,7 @@ use strict; use warnings; use lib 't/lib'; +use VPIT::TestHelpers; use Thread::Cleanup::TestThreads; use Test::More 'no_plan'; @@ -11,6 +12,7 @@ use Test::More 'no_plan'; use Thread::Cleanup; my %called : shared; +my $destr : shared; my %nums : shared; our $x = -1; @@ -27,8 +29,14 @@ Thread::Cleanup::register { lock %nums; $nums{$tid}; }; - is $x, $num, "\$x in destructor of thread $tid"; + + my $gd = do { + lock $destr; + (defined $destr && $destr =~ /\[$tid\]/) ? 1 : undef; + }; + is $gd, undef, "thread $tid destructor fires before global destruction"; + local $x = $tid; }; @@ -43,6 +51,14 @@ sub cb { $ran{$tid}++; } + my $immortal = VPIT::TestHelpers::Guard->new(sub { + # It seems we can't lock aggregates during global destruction, so we + # resort to using a string instead. + lock $destr; + $destr .= "[$tid]"; + }); + $immortal->{self} = $immortal; + { lock %nums; $nums{$tid} = $y;