#!/usr/bin/perl -w
use threads;
use threads::shared;
use Thread::Pool::Simple;
my $sum:shared;
$sum=0;
my $pool=Thread::Pool::Simple->new(
min=>2,
max=>3,
load=>10,
do=>[\&count],
passid=>0,
lifespan=>10000
);
my $i;
for($i=2;$i<=100000;$i+=100)
{
my $j=$i-100;
$pool->add($j,$i);
}
$pool->join();
print "$sum\n";
sub count()
{
my $start=shift;
my $end=shift;
my $tmp;
for($tmp=$start;$tmp<$end;$tmp++)
{
$sum+=$tmp;
}
}
转载于:https://blog.51cto.com/biott/1109932