Hi, I tried what you said about Thread::Pool, and all the threads get started correctly but once I get to the 'if statement' that kills the threads, the foreach loop, get stuck in a infinte loops. I pasted some of my code in here, with a dummy sub function I created to test the pools. Any idea why the 'if(@result = $pool->result_dontwait($_))' statement never hits true??
-Otter
my %hosts=();
my $counter=0;
my $global=0;
my $pool=();
my @result=();
my %ids=();
$pool = Thread::Pool->new(
{
do => sub {\&Temp_function(@_);},
workers => 10, # default: 1
});
%hosts = &Telnet_host();
foreach (keys %hosts)
{
$ids{$_}=$pool->job($_, $hosts{$_} );
}
while (keys %ids)
{
foreach (keys %ids)
{
if (@result = $pool->result_dontwait($_))
{
print $ids{$_} . "\n";
delete ($ids{$_});
}
}
print "Items still to do: " . $pool->todo . "\n";
}
##--END FUNCTION CALLs--
### Temp Sub Functions
sub Temp_function
{
my ($ip,$mac)= @_;
print $mac . "\n";
return $mac;
}
### End Temp Sub Functions
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.