Blanchette, Marco wrote: > my @thr; > for (my $i=0;$i<=$#ARGV;$i++){ > push @thr, threads->new(\&extractSeq, $ARGV[$i]); > if (scalar(@thr) == $opt_p || $i == $#ARGV){ > print "Running ",scalar(@thr)," parallel jobs\n"; > $_->join for @thr; > undef @thr; > } > }
Your job control is running in batches of $opt_p with each batch running until all jobs are complete. This is inefficient. Try the following: foreach my $arg (@ARGV) { # New parallel job threads->new(\&extractSeq, $arg); # If max parallel count, then wait for some threads to finish while (threads->list(threads::running) >= $opt_p) { if (my @thrs = threads->list(threads::joinable)) { $_->join() foreach @thrs; } else { sleep(1); } } } # Wait for all running threads to finish $_->join() foreach threads->list();