Hello
Im writing perl scripts that use threads.
Mi goal is that each thread could process an element of an array that has 10 elements, so thread0 process array[0], thread1 process array[1] and so on until thread9 process array[9]
Those 10 lines come from a file that Perl reads in chunks of ten lines until EOF, something like this
while (<FILE>) { push @buffer, $_; $i++; if ($i == 10) { $i = 0; processthreads (@buffer); @buffer = (); } }
My problem is the next
After processing like 200 chunks of the file (2000 lines) I get the following error
Out of memory! Segmentation Fault
I supposed that is because each thread that Perl have created from the beginning still is living.
I supposed that each thread is destroyed when it finish, it seems that my script is not correct and that each threads lives, how can I kill a thread??
Below is my code.
Please help, thanks in advanced
open(INPUT, $file) or die "No puedo leer del log: $! $file"; while (<INPUT>) { push @buffer, $_; $i++; if ($i == 10) { $i = 0; processthreads (@buffer); @buffer = (); } } close (INPUT); }
sub processthreads() {
my @arreglo = (); @arreglo = shift;
$thr0 = new threads \&proceso, $arreglo[0]; $thr1 = new threads \&proceso, $arreglo[1]; $thr2 = new threads \&proceso, $arreglo[2]; $thr3 = new threads \&proceso, $arreglo[3]; $thr4 = new threads \&proceso, $arreglo[4]; $thr5 = new threads \&proceso, $arreglo[5]; $thr6 = new threads \&proceso, $arreglo[6]; $thr7 = new threads \&proceso, $arreglo[7]; $thr8 = new threads \&proceso, $arreglo[8]; $thr9 = new threads \&proceso, $arreglo[9]; $thr0->detach; $thr1->detach; $thr2->detach; $thr3->detach; $thr4->detach; $thr5->detach; $thr6->detach; $thr7->detach; $thr8->detach; $thr9->detach;
} sub proceso () { my ($linea):shared = ""; my (@normal):shared = (); my ($time):shared = ""; my ($count):shared = 0; my (@buffer) = (); $linea = shift;
@normal = $linea =~ / (.*?)\s (.*?)\s (.*?)\s (.*?)\s (.*?)\s (.*?)\s (.*?)\s (.*?)\s (.*?)\s (.*) /x;
if ($normal[0] eq '-') { $normal[0] = "none"; } if (! defined $normal[0]) { $normal[0] = "none"; } if ($normal[1] eq '-') { $normal[1] = 0; } if (! defined $normal[1]) { $normal[1] = 0; }
if ($normal[2] eq '-') {$normal[2] = "none"; }
if (! defined $normal[2]) { $normal[2] = "none"; }
if ($normal[3] eq '-') { $normal[3] = "none"; } if (! defined $normal[3]) { $normal[3] = "none"; }
if ($normal[4] eq '-') { $normal[4] = 0; } if (! defined $normal[4]) { $normal[4] = 0; }
if ($normal[5] eq '-') { $normal[5] = "none"; } if (! defined $normal[5]) { $normal[5] = "none"; }
if ($normal[6] eq '-') { $normal[6] = "none"; } if (! defined $normal[6]) { $normal[6] = "none"; }
if ($normal[7] eq '-') {$normal[7] = "none"; } if (! defined $normal[7]) { $normal[7] = "none"; }
if ($normal[8] eq '-') { $normal[8] = "none"; } if (! defined $normal[8]) { $normal[8] = "none"; }
if ($normal[9] eq '-') { $normal[9] = "none"; } if (! defined $normal[9]) { $normal[9] = "none"; }
$time = scalar localtime($normal[0]); }
-- If I have seen further it is by standing on the shoulders of the giants Isaac Newton
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>