CPAN::Forum
threads - Re: Memory leak, possibly in shared pool
| Posted on Fri Sep 15 21:02:19 2006 by jdhedden in response to 3033 (See the whole thread of 5) |
| Re: Memory leak, possibly in shared pool |
|
I think I have traced the problem to the use of semaphores.
I'm still researching the problem, but here's a sample
program that exhibits the bug:
use threads;
use Thread::Semaphore;
my $sema = Thread::Semaphore->new();
for (1..100000) {
$sema->down();
$sema->up();
}
sleep(15);
As an aside, I noted you're using way too much code in
dealing with shared variables. For instance, the following
at line 474:
my $cmdlist;
&threads::shared::share( \$cmdlist );
$cmdlist = &threads::shared::share([]);
push( @{$cmdlist}, $filename, @cmd );
$thrUpdateQueue->enqueue( $cmdlist );
$cmdlist = undef;
Can be simplified to:
my @cmdlist :shared;
push(@cmdlist, $filename, @cmd);
$thrUpdateQueue->enqueue(\@cmdlist);
Similarly, you can simplify rrdUpdateThread() (at line 499):
# A background thread that updates RRD files
sub rrdUpdateThread
{
&Torrus::Log::setTID(threads->tid());
while (my $cmdlist = $thrUpdateQueue->dequeue()) {
if (isDebug) {
Debug("Updating RRD: " . join(' ', @{$cmdlist}));
}
$rrdtoolSemaphore->down();
RRDs::update(@{$cmdlist});
my $err = RRDs::error();
$rrdtoolSemaphore->up();
if ($err) {
Error('ERROR updating' . $cmdlist->[0] . ': ' . $err);
$thrErrorsQueue->enqueue($cmdlist->[0]);
}
}
}
The above has the added value that you can terminate the
thread (if desired) simply by enqueuing an 'undef'.
|
| Write a response |
(0)
]