X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F10-join.t;h=a3be76159b774bd392d499623d3c3b9b58e47fee;hb=HEAD;hp=b3f92c2a6c552469ae0d8b8021408f1b3e5b4aca;hpb=15b9171b2fc61b12e0dcc123369fc2b66fe87012;p=perl%2Fmodules%2FThread-Cleanup.git diff --git a/t/10-join.t b/t/10-join.t index b3f92c2..a3be761 100644 --- a/t/10-join.t +++ b/t/10-join.t @@ -3,24 +3,16 @@ use strict; use warnings; -use Config qw/%Config/; +use lib 't/lib'; +use VPIT::TestHelpers; +use Thread::Cleanup::TestThreads; -BEGIN { - if (!$Config{useithreads}) { - require Test::More; - Test::More->import; - plan(skip_all => 'This perl wasn\'t built to support threads'); - } -} - -use threads; -use threads::shared; - -use Test::More tests => 5 * (2 + 2) + 1; +use Test::More 'no_plan'; use Thread::Cleanup; my %called : shared; +my $destr : shared; my %nums : shared; our $x = -1; @@ -37,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; }; @@ -53,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; @@ -61,19 +67,15 @@ sub cb { local $x = -$tid; } -my @tids; -my @t = map { +my @threads = map { local $x = $_; - my $thr = threads->create(\&cb, $_); - push @tids, $thr->tid; - $thr; + spawn(\&cb, $_); } 0 .. 4; -diag "Using threads $threads::VERSION"; -diag "Using threads::shared $threads::shared::VERSION"; +my @tids = map $_->tid, @threads; -$_->join for @t; +$_->join for @threads; is $x, -1, '$x in the main thread';