Thanks again. This indeed works perfectly.
I do have one more question. One of the things my 'process_genome' subroutine has to do is to run a few perl scripts (from JBrowse browser package, if it's of interest).

I did not write those scripts and have no control over them. These scripts require to be run in the "correct" directory (they do stuff in the working directory rather then ask a directory path as an argument). So. my 'process_genome' has to 'chdir' to the genome directory. However, as I learned the current directory is shared by all threads, I was suggested to write the following wrapper:

# forks then changes working directory and executes a command sub chdir_and_system { my ( $dir, @exec_args ) = @_; my $pid = fork; die "couldn't fork: $!" unless defined $pid; unless ($pid) { # this is the child chdir($dir); # open STDOUT, ">/dev/null"; # silence subprocess output # open STDERR, ">/dev/null"; # silence subprocess stderr system(@exec_args) == 0 or die "system @exec_args failed"; } wait; die "child error $?" if ($?); }
then call each of the external scripts using something like this:
sub add_gff_track { my ( $browser_project_dir, $gff_file, $track_label, $key, @optiona +l_args ) = @_; my @args = ( "bin/flatfile-to-json.pl", "--gff=$gff_file", "--tracklabel=$track_label", "--key=$key", @optional_args ); chdir_and_system( $browser_project_dir, @args ); }
I was originally suggested to use 'exec' in the wrapper, but after some reading I thought that perhaps 'system' should be used. I'm not sure. the thing is I need to know that when this wrapper sub ends, the system command also ended (other command might rely on its output). I'm also not sure if all the wrapper logic is OK. Bottom line, my threads terminate abnormally. Perhaps the JBrowse scripts don't return a good value even if they succeed?

How would you go about this?


In reply to Re^6: Multi-threads newbie questions by daverave
in thread Multi-threads newbie questions by daverave

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.