Change the line to $MAX_THREADS = 100;!? As this answer is more than trivial, what are you really asking ? Could you rephrase your question?

UPDATE: Got it. You want to know how to limit the total number of threads run in one session

First of all, if you post something here on perlmonks, use <code> and </code> to enclose your code, it is really hard to read without indentation

You might just change the thread creation loop to this:

my $LIFETIME_THREADS=100; while (! $TERM) { for (my $needed = $MAX_THREADS - threads->list(); $needed && ! $TERM; $needed--) { # New thread threads->create('worker', $queue, $TIMEOUT) if ($LIFETIME_THREADS- +- >0); exit(0) if (threads->list()==0); } # Wait for any threads to finish sleep(1); }

2ND UPDATE: As AnonMonk observed, the loop runs through even after $LIFETIME_THREADS reaches 0, so $LIFETIME_THREADS gets negative. Testing for 0 isn't enough here. Corrected now.


In reply to Re: how to limit maximum threads in cpan example boss.pl by jethro
in thread how to limit maximum threads in cpan example boss.pl by franc1967

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.