]> git.vpit.fr Git - perl/modules/Lexical-Types.git/blob - t/81-threads-teardown.t
Do nothing after that the thread local storage has been freed
[perl/modules/Lexical-Types.git] / t / 81-threads-teardown.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use lib 't/lib';
7 use VPIT::TestHelpers;
8 use Lexical::Types::TestThreads;
9
10 use Test::More tests => 2;
11
12 {
13  my $status = run_perl <<' RUN';
14   { package IntX; package IntY; package IntZ; }
15   my ($code, @expected);
16   sub cb {
17    my $e = shift(@expected) || q{DUMMY};
18    --$code if $_[0] eq $e;
19    ()
20   }
21   use threads;
22   $code = threads->create(sub {
23    $code = @expected = qw<IntX>;
24    eval q{use Lexical::Types as => \&cb; my IntX $x;}; die if $@;
25    return $code;
26   })->join;
27   $code += @expected = qw<IntZ>;
28   eval q{my IntY $y;}; die if $@;
29   eval q{use Lexical::Types as => \&cb; my IntZ $z;}; die if $@;
30   $code += 256 if $code < 0;
31   exit $code;
32  RUN
33  is $status, 0, 'loading the pragma in a thread and using it outside doesn\'t segfault';
34 }
35
36 {
37  my $status = run_perl <<' RUN';
38   use threads;
39   BEGIN { require Lexical::Types; }
40   sub X::DESTROY {
41    eval 'use Lexical::Types; package Z; my Z $z = 1';
42    exit 1 if $@;
43   }
44   threads->create(sub {
45    my $x = bless { }, 'X';
46    $x->{self} = $x;
47    return;
48   })->join;
49   exit 0;
50  RUN
51  is $status, 0, 'Lexical::Types can be loaded in eval STRING during global destruction at the end of a thread';
52 }