Reputation: 23275
sub test {
$val = shift;
print $val * 2;
}
for $i (1..1000)
{
test($i);
}
How can I get the calls to test
to be executed in concurrent threads using Thread::Pool or Thread::Pool::Simple ?
Upvotes: 2
Views: 93
Reputation: 23275
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";
Upvotes: 2