Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Proper way to thread this in PERL.

by jethro (Monsignor)
on Dec 25, 2013 at 20:33 UTC ( #1068369=note: print w/ replies, xml ) Need Help??


in reply to Proper way to thread this in PERL.

I'm no threads expert but one thing I see problematic in your code is that you use sleep as a crude delimiter of threads in the hope that 5 threads per 5 seconds is not too much. Much better would be to check for number of threads with scalar(threads->list()) and sleep as long as this number is at maximum. Only when that number goes down another thread should be generated

Something like this:

while (threads->list()<$threadsmax) { sleep(1); # or threads->yield; but I'm not sure what happens if you +call this in the main thread } print ".";

I added the print for debugging purposes. If you see that no new "." get printed after a while it would mean no threads finish.


Comment on Re: Proper way to thread this in PERL.
Download Code
Re^2: Proper way to thread this in PERL.
by tekio (Novice) on Dec 25, 2013 at 21:33 UTC
    Thank you! I will give that a try!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1068369]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (17)
As of 2014-07-29 19:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (226 votes), past polls