File: threads.t

package info (click to toggle)
perl 5.42.0-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 128,392 kB
  • sloc: perl: 534,963; ansic: 240,563; sh: 72,042; pascal: 6,934; xml: 2,428; yacc: 1,360; makefile: 1,197; cpp: 208; lisp: 1
file content (47 lines) | stat: -rw-r--r-- 980 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
#!./perl

BEGIN {
    chdir 't' if -d 't';
    require './test.pl';
    set_up_inc('../lib');
    require Config;

    skip_all_without_config('useithreads');
    skip_all_if_miniperl("no dynamic loading on miniperl, no threads");
}

use v5.36;
use feature 'class';
no warnings 'experimental::class';

use threads;

class Testcase1 {
    field $x :param;
    method x { return $x }
}

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

{
    my $obj = Testcase1->new(x => 10);
    threads->create(sub {
        is($obj->x, 10, '$obj->x inside thread created before');
    })->join;
    next_test(); # account for is() inside thread
}

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

done_testing;