use threads;
use Thread::Queue;
our $KIDS = $count > 20? 10 : int ($count / 4) || 1; # Some way to control max # of threads
my $work_Q = new Thread::Queue;
## Start the kids
my @kids = map{ threads->create( \&kid, $_) } 1 .. $KIDS;
$work_Q->enqueue( keys %ServerInfo ); # Feed the QUEUE with work to do ....
## Tell them to stop
$work_Q->enqueue( (undef) x $KIDS ); # THis tells each thread to QUIT
## And wait for Kids to finish..
my %results = map {$_->join} @kids;
#----------------------------------------------------
sub kid {
my $kidnumber = shift;
my @results=();
my $tid = threads->tid;
my $count=0;
my $pinger = Net::Ping->new("icmp",$TimeOut);
#printf "Kid: %02d started
\n", $tid;
while( my $work = $work_Q->dequeue ) {
$count ++;
push @results, $work, Ping_it($pinger, $work) ;
}
push @results,"KID$kidnumber",$count;
#print "kid: $tid ending after processing $count items.
\n";
return @results;
}