I'd recommend that you start out working with one thread, then two, three, etc. until you get a feel for threads. I couldn't replicate your error, but then I didn't use threads the same as you. Here's a simplified script to check the
number of threads enqueued:
#!/usr/bin/perl -l
BEGIN {
$| = 1;
$^W = 1;
}
use strict;
use warnings;
use threads;
use Thread::Queue;
use LWP::UserAgent;
use constant THREADS => 3;
my(@urls) = (
'http://search.cpan.org',
'http://www.perl.org',
'http://www.cpan.org',
);
my $workq = Thread::Queue->new;
my $thr = threads->create( sub {
while(defined(my $url = $workq->dequeue)) {
do {
my $ua = LWP::UserAgent->new;
foreach my $url (@urls) {
my $response = $ua->get($url);
if ($response->is_success) {
print $response->decoded_content;
}
else {
die $response->status_line;
}
}
};
}
});
$workq->enqueue($urls[0], $urls[1], $urls[2]);
my $num_working = $workq->pending();
print $num_working;
$workq->end();
$thr->detach();
undef $thr;