File: threads.t

package info (click to toggle)
libmath-bigint-gmp-perl 1.7003-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,016 kB
  • sloc: pascal: 3,998; perl: 280; makefile: 9; sh: 1
file content (36 lines) | stat: -rw-r--r-- 638 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
# -*- mode: perl; -*-

use strict;
use warnings;

use Test::More;

use Config;

BEGIN {
    plan skip_all => 'Perl compiled without ithreads'
        unless $Config{useithreads};
    plan skip_all => 'ithreads support requires perl 5.8 or newer'
        unless $] >= 5.008000;
    plan tests => 22;
}

use threads;

use Math::BigInt only => 'GMP';

my @threads = map {
    my $x = $_;
    threads->create(sub {
        (Math::BigInt->new($x))
    });
} 0 .. 19;

my @ret = map {
    $_->join
} @threads;

pass 'we survived our threads';

is(@ret, 20, 'got all the numbers we expected');
is($ret[$_], $_, 'numbers look sane') for 0 .. 19;