problem with ithreads

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!


I have FreeBSD 4.9 and Perl 5.8.6 with useithreads=define installed.

I run my script (source in the and of the message) and it works OK for 15-30
minutes. After that it slows down and soon freezes. I put counter in while
loop of thread_do sub to count how many requests each thread do. Each thread
do 100-150 requests and after that die. When I send INT signal after script
worked for 40 minuets I get message: "A thread exited while 4 threads were
running". I tried to put the body of loop into eval block but it didn't

Why thread die after and how to fix solve problem? Please, help me.

use strict;
use threads;
use threads::shared;
use Thread::Queue;
use LWP::UserAgent;
use HTTP::Request::Common;

$| = 1;

my $thread_num : shared = 0;
my $max_thread = 50;
my $exit = 0;
my $result_q = Thread::Queue->new();

threads->new(\&thread_do) for (1..$max_thread);

while (!$exit) {
    for (my $i = 0; $i < $result_q->pending(); $i++) {
        print $result_q->dequeue() . "\n";

print "Done\n";

sub thread_do
    my $tid = threads->self->tid();
    while (1) {
        my $ua = LWP::UserAgent->new(timeout => 3);
        my $res = $ua->request(HEAD '');
        $result_q->enqueue("$tid;" . $res->code() . ";" . $res->message() .

Site Timeline