File: 32threads.t

package info (click to toggle)
libobject-pad-perl 0.821-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 936 kB
  • sloc: ansic: 3,361; perl: 3,328; pascal: 28; makefile: 3
file content (58 lines) | stat: -rw-r--r-- 1,188 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/perl

use v5.18;
use warnings;

use Test2::V0;
use Test2::IPC;

use Object::Pad 0.800;

eval { require Config && $Config::Config{useithreads} } or
   plan skip_all => "This perl does not support threads";

require threads;

class Cnative :repr(native) {
   field $x :param;
   method x { return $x }
}

class CHASH :repr(HASH) {
   field $x :param;
   method x { return $x }
}

package CmagicBase { sub new { return bless {}, shift } }
class Cmagic :isa(CmagicBase) :repr(magic) {
   field $x :param;
   method x { return $x }
}

{
   my $ret = threads->create(sub {
      pass( "Created dummy thread" );
      return 1;
   })->join;
   is( $ret, 1, "Returned from dummy thread" );
}

foreach my $repr (qw( native HASH magic )) {
    my $class = "C$repr";

    subtest "Class using :repr($repr)" => sub {
        {
           my $obj = $class->new( x => 10 );
           threads->create(sub {
              is( $obj->x, 10, '$obj->x inside thread created before' );
           })->join;
        }

        threads->create(sub {
           my $obj = $class->new( x => 20 );
           is( $obj->x, 20, '$obj->x created inside thread' );
        })->join;
    }
}

done_testing;