在perl中使用并发线程的简单方法?

时间:2016-09-09 04:59:23

标签: multithreading perl concurrency

NSTimeZone.defaultTimeZone()

如何使用Thread::PoolThread::Pool::Simple在并发线程中执行对sub test { $val = shift; print $val * 2; } for $i (1..1000) { test($i); } 的调用?

1 个答案:

答案 0 :(得分:2)

use feature 'say';
use Thread::Pool::Simple;

sub test
{
    say shift;
    sleep(5);
}


my $pool = Thread::Pool::Simple->new (

    do => [\&test],

    min => 10,
    max => 20


);

$pool->add($_) for (1..50);
$pool->join;
say "Finished";