Perl Multithreading and Signal control

Source: Internet
Author: User
Tags semaphore

#!/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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.