#!/usr/bin/perluse strict;use warnings;use threads;use thread::semaphore;my $max _thread = 5;my $semaphore = Thread:: Semaphore->new ($max _thread); Sub testfun{$semaphore->up ();} for (My $index = 1; $index <=; $index + +) {$semaphore->down (); My $thread = Threads->create (\&testfun); $thre Ad->detach ();} Waitquit (); <pre name= "code" class= "plain" >sub waitquit{my $num = 0;while ($num < $max _thread) {$semaphore Down (); $num + +;}}
#!perluse warnings;use strict;use threads;use thread::semaphore;die "perl $ <thread> <blastConfig> <pep || Dna>perl $3 Blast.config dna\n "if @ARGV! = 3;my $max _thread = $ARGV [0];my $semaphore = Thread::semaphore->new ($ma X_thread); mkdir "Compliantfasta"; chdir "Compliantfasta"; open FA, ". /$ARGV [1] "or Die $!; while (<FA>) {chomp;my @tmp = split; $semaphore->down (); My $thread = Threads->create (\&adjust, $tmp [0], $ TMP[1]); $thread->detach ();} &wait;chdir "."; My $len = 0;my ($type, $p), if ($ARGV [2] =~/dna/i) {$len =; $type = "F"; $p = "Blastn";} elsif ($ARGV [2] =~/pep/i) {$len = ten; $type = "T"; $p = "BLASTP";} ' Orthomclfilterfasta compliantfasta $len '; ' Formatdb-i goodproteins.fasta-p $type '; mkdir "splitblast"; ' Perl split_ fasta.pl Goodproteins.fasta 8 splitblast/blast '; my @blast = ' ls splitblast/* '; my $sp 2 = thread::semaphore->new (8); foreach my $i (@blast) {chomp ($i); $sp 2->down (); My $thread = Threads->create (\&blast, $i, $p, $ARGV [0]); $Thread->detach ();} &wait2; ' cat splitblast/*.out > All.blast '; ' Orthomclblastparser all.blast compliantfasta > SimilarSequences.txt '; ' rm all.blast-rf '; Sub Blast{my ($f, $t, $p) = @_; ' Blastall-p $t-i $f-D goodproteins.fasta-m 8- F f-b 1000-v 1000-a $p-o $f. Out '; $sp 2->up ();} Sub Wait2{my $num = 0;while ($num < 8) {$sp 2->down (); $num + +;}} Sub Adjust{my ($label, $path) = @_; ' Orthomcladjustfasta $label $path 1 '; $semaphore->up ();} Sub Wait{my $num = 0;while ($num < $max _thread) {$semaphore->down (); $num + +;}}
Perl Multithreading and Signal control