]> git.vpit.fr Git - perl/modules/Lexical-Types.git/blob - t/30-threads.t
Use a pointer table allocated on shared memory
[perl/modules/Lexical-Types.git] / t / 30-threads.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Config qw/%Config/;
7
8 BEGIN {
9  if (!$Config{useithreads}) {
10   require Test::More;
11   Test::More->import;
12   plan(skip_all => 'This perl wasn\'t built to support threads');
13  }
14 }
15
16 use threads;
17
18 use Test::More tests => 10 * 2 * 2 * (1 + 2);
19
20 {
21  package Lexical::Types::Test::Tag;
22
23  sub TYPEDSCALAR {
24   my $tid = threads->tid();
25   my ($file, $line) = (caller(0))[1, 2];
26   my $where = "at $file line $line in thread $tid";
27   Test::More::is($_[0], __PACKAGE__, "base type is correct $where");
28   Test::More::is($_[2], 'Tag', "original type is correct $where");
29   $_[1] = $tid;
30   ();
31  }
32 }
33
34 { package Tag; }
35
36 use Lexical::Types as => 'Lexical::Types::Test::';
37
38 sub try {
39  my $tid = threads->tid();
40
41  for (1 .. 2) {
42   my Tag $t;
43   is $t, $tid, "typed lexical correctly initialized at run $_ in thread $tid";
44
45   eval <<'EVALD';
46    use Lexical::Types as => "Lexical::Types::Test::";
47    my Tag $t2;
48    is $t2, $tid, "typed lexical correctly initialized in eval at run $_ in thread $tid";
49 EVALD
50   diag $@ if $@;
51  }
52 }
53
54 my @t = map threads->create(\&try), 1 .. 10;
55 $_->join for @t;