Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^3: Perl detached threads, loops & my?

by rjt (Deacon)
on Jun 09, 2010 at 00:27 UTC ( #843769=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Perl detached threads, loops & my?
in thread Perl detached threads, loops & my?

Thank you for the example. However, I still have doubts. Please carefully consider this reply, my other reply, and BrowserUk's comments.

Red flag for me: Your second script, you claim takes "HOURS" to run. On the below mentioned old system, that script completes for me in minutes. Process memory usage never went above 50MB.

$ time perl script.pl Called: 0 Called: 1 : Called: 99998 Called: 99999 real 12m23.351s user 10m50.800s sys 0m23.580s

You're trying to create 100000 threads. You invite a race condition where your script may hit a wall very quickly if your threads do anything non-trivial. You would expect to see:

Called: 367 Called: 368 Thread creation failed: pthread_create returned 11 at script line 4. Can't call method "detach" on an undefined value at script line 5.

Your first example will "leak" memory in the sense that the @thr_ll array will grow to 100000, even after threads exit. On most systems this wouldn't be a big deal if your real application caps at 100000 as well, but I still wouldn't recommend it.

I ran both of your scripts on my oldest machine, and neither one had a deleterious effect on Perl 5.10.1 on Ubuntu, running on an 8 year old P4-1.6GHz machine with 512MB. Both ran to completion.


Comment on Re^3: Perl detached threads, loops & my?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2014-08-21 04:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (127 votes), past polls