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.
In reply to Re^3: Perl detached threads, loops & my?
by rjt
in thread Perl detached threads, loops & my?
by expresspotato
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |