NSTimeZone.defaultTimeZone()
如何使用Thread::Pool或Thread::Pool::Simple在并发线程中执行对sub test {
$val = shift;
print $val * 2;
}
for $i (1..1000)
{
test($i);
}
的调用?
答案 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";