http://qs321.pair.com?node_id=237094


in reply to •Re: Run N similar tasks in parallel
in thread Run N similar tasks in parallel

++merlyn for checking fork's return value, that I forgot.

Please, can you explain why your approach is more robust? I am really interested in it!

Ciao and thanks!
--bronto


The very nature of Perl to be like natural language--inconsistant and full of dwim and special cases--makes it impossible to know it all without simply memorizing the documentation (which is not complete or totally correct anyway).
--John M. Dlugosz

Replies are listed 'Best First'.
•Re: Re: •Re: Run N similar tasks in parallel
by merlyn (Sage) on Feb 20, 2003 at 14:58 UTC
    By checking the possible failure of fork, I never "think" I'm working on five kids when only two have really started.

    By checking the value of waitpid for a possible -1 return, I never "think" I have kids left when I really don't. The -1 force-resets the hash.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      By checking the value of waitpid for a possible -1 return, I never "think" I have kids left when I really don't. The -1 force-resets the hash.

      Good, I should check for the return value of wait as well. Thanks.

      Sorry if I am bothering you about this, but I am missing an information: why do you prefer waitpid to wait? Flexybility? Possibility to make waitpid a non-blocking call? What?

      Thanks in advance.

      --bronto


      The very nature of Perl to be like natural language--inconsistant and full of dwim and special cases--makes it impossible to know it all without simply memorizing the documentation (which is not complete or totally correct anyway).
      --John M. Dlugosz
        Possibility to make waitpid a non-blocking call?
        Ahh, yes. That's it. Although my little snippet of code would never need to wait for more than one process (it'll just loop the outer loop if the waited process is not one of our kids), there are times when I would change just that part of the loop to a "wait until there are no more kids" before moving on.

        So, I'm a bit more familiar with waitpid now, and it makes it easy to step sideways to the multi-wait loop.

        -- Randal L. Schwartz, Perl hacker
        Be sure to read my standard disclaimer if this is a reply.