Dear Masters,

I'm relatively new to Perl.

I'm with a multi-thread dilemma :).

To implement a multitask environment I used Forks (Parallel::ForkManager). But I think forking is not the solution I need.

I create 50 forks each one is responsible for parsing a stream.

But if one of the streams is bigger than the other 49, these 49 instead of starting to parse new streams they have to wait for the one that is taking more time to process.

How can I "unblock" the other threads? Is forking the solution?

My code:

my $pm = Parallel::ForkManager->new(50); my $i = 0; while(i<50){ $pm->start and next; processStream($stream); $i++; $pm->finish; # do the exit in the child process } $pm->wait_all_children();

If I remove wait_all_children() what would happen?

Best Regards, thank you for your help.


In reply to Fork vs pThreads by ThelmaJay

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.