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;
|