2
sub test {
$val = shift;
print $val * 2;
}
for $i (1..1000)
{
test($i);
}
如何使用Thread::Pool或Thread::Pool::Simple可以在併發線程中執行test
的調用?在perl中使用併發線程的簡單方法?
sub test {
$val = shift;
print $val * 2;
}
for $i (1..1000)
{
test($i);
}
如何使用Thread::Pool或Thread::Pool::Simple可以在併發線程中執行test
的調用?在perl中使用併發線程的簡單方法?
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";
您可以將自己的答案標記爲已接受。請參閱:http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work –