my $url_q = Thread::Queue -> new();
sub http_fetch_thread
{
my $ua = LWP::UserAgent -> new();
$ua -> timeout ( 10 );
while ( my $item = $url_q -> dequeue() )
{
my $url = "http://www." . $item . ".com";
<... fetch stuff ... >
}
}
####
for ( 1..$thrCount )
{
threads -> create ( \&http_fetch_thread );
}
open ( my $contents, "<", $contents_file_name ) or die $!;
$url_q -> enqueue ( <$contents> );
$url_q -> end;
close ( $contents );
#wait for completion
foreach my $thr ( threads -> list() )
{
$thr -> join(); #not capturing return code, we started in a void context.
}
print "At program completion, total count was ", $totalCount,"\n";
####
while ( threads -> list )
{
foreach my $thread ( threads -> list ( threads::joinable ) )
{
$thread -> join();
}
print $totalCount,"\n";
sleep 5;
}