problem with ithreads
From: Oleg Feotast (feotast_at_feotast.net)
Date: 12/29/04
- Previous message: Kevin Buzzard: "Re: 2 versions of a module installed?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 29 Dec 2004 20:26:16 +0200
Hi.
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
worked.
Why thread die after and how to fix solve problem? Please, help me.
#!/usr/bin/perl
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
{
threads->self->detach();
my $tid = threads->self->tid();
while (1) {
my $ua = LWP::UserAgent->new(timeout => 3);
my $res = $ua->request(HEAD 'http://microsoft.com/');
$result_q->enqueue("$tid;" . $res->code() . ";" . $res->message() .
";");
}
}
- Previous message: Kevin Buzzard: "Re: 2 versions of a module installed?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|