in reply to Perl detached threads, loops & my?
We need more information. What does @go_do_something contain? How many threads are you trying to create? What are they doing? In other words, can you give us a runnable but minimal example that exhibits the behavior on your system?
Memory leak? Maybe, but, again, a real example would be necessary, here, plus some information on how you're measuring the memory and determining there is a leak.
You said it "crashes the program without any error message". Is it possible that your script just decided it was done creating threads and exited on its own? That would produce behavior consistent with what you are seeing. Since you've detached every thread, once your @go_do_something loop exits, how do you know (in your code) that all of your threads have finished and it is safe to exit your program? What was its exit status when execution was complete? I might be completely missing the issue, here, but with the limited information available, this really seems most likely to me.
Maybe you have a valid reason for detaching everything, but if you want to be sure all threads have finished, you might consider something along the lines of:
use warnings; use strict; use threads; use feature 'say'; my @go_do_something = (1 .. 10); sub some_sub { say "Thread #$_ started"; sleep(rand(10)); say "Thread #$_ complete"; } my @threads; push @threads, threads->new(\&some_sub, $_) for @go_do_something; say "All threads started."; $_->join for @threads; say "All threads joined. Exiting.";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl detached threads, loops & my?
by expresspotato (Beadle) on Jun 09, 2010 at 01:56 UTC | |
by BrowserUk (Patriarch) on Jun 09, 2010 at 02:23 UTC | |
by rjt (Curate) on Jun 09, 2010 at 03:08 UTC |