in reply to Re: Trouble implementing threads
in thread Trouble implementing threads

Dear monks I have modified as per zentara's advice but now it goes into a endless loop and get's killed ultimately. can some one help me in this.

use threads ; use feature "say"; #use strict; use warnings; `tr -d '\n' </home/guru/Desktop/sequence.fasta >modified_human_chr_1.t +xt`; my $input_file = "modified_human_chr_1.txt"; open my $hd, "<", $input_file or die "Couldn't open '$input_file' - $! +"; my $text=<$hd>; chomp($text); my $window=5; my $i=0; LOOP:seek $hd,$i,0; read ($hd,my $substring,$window); my %hash; if(length($substring)==$window) { $hash{$substring}=$i; $i++; goto LOOP; } my $count = keys %hash; my $j=0; foreach my $pattern (keys %hash) { if($j<=$count) { my $thr="thread".$j; $$thr=threads->create(\&hunter,$text,$pattern); $j++; } } my @returns; foreach $thread (threads->list) { if ($thread->is_joinable() ) { push @returns, $thread->join; } if( scalar (threads->list) == 0 ) {last;} } print "@returns\n"; sub hunter { my ($text,$pattern) = @_ ; my $offset = 0; print "\n$pattern ($window)\n"; print '~' x $window,"\n"; my $pos=index $text,$pattern,$offset; while ($pos != -1) { print $pos+1," to ",$pos+$window,"\n"; $offset = $pos + 99; $pos = index($text, $pattern, $offset); } }

Replies are listed 'Best First'.
Re^3: Trouble implementing threads
by zentara (Cardinal) on Oct 21, 2011 at 11:14 UTC
    To be honest, I can't understand what you are doing in your code, with the goto LOOP and the seek. Your first step should be to see how many threads are being created, you may have a thread bomb in your code. How many threads are reportedly created by the printout of $j, and how much memory are you consuming. Try watching the script with top, and see how much memory you use.

    You should strip down your code, to the point where you are just creating and joining threads which do nothing. When you get that to work, start adding your math routines, and see where it starts to break down.


    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh