in reply to how to limit maximum threads in cpan example boss.pl
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: how to limit maximum threads in cpan example boss.pl
by Anonymous Monk on Aug 11, 2008 at 12:38 UTC | |
by franc1967 (Initiate) on Aug 11, 2008 at 16:05 UTC | |
|
Re^2: how to limit maximum threads in cpan example boss.pl
by Anonymous Monk on Aug 11, 2008 at 12:21 UTC |