RobCheung has asked for the wisdom of the Perl Monks concerning the following question:
Taking the above codes as an example, I found that not every thread is
re-collected right after the join is completed when using join to
perform the re-collection job. The memory will be re-cycled after all
the thread in @thread has been "join". When applying to a practial
job, it will be not satisfied. However, if using
"threads->new("StartTest")->detach" directly, there is no such
problem. Why?
-----------8<------------
#!/usr/bin/Perl use 5.008; use strict; use threads; use threads::shared; $| = 1; my @threads; foreach (1 .. 20) { push @threads, threads->new('StartTest'); # threads->new('StartTest')->detach; threads->yield; } while (my $thread = shift @threads) { $thread->join; } sleep 10; print "\n", "All threads done\n"; sub StartTest { my $self = threads->self; my @m = (1 .. 99999); print "Thread ", $self->tid, " started\n"; sleep ($self->tid + 5); print "Thread ", $self->tid, " ending\n"; } 1; __END__
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: The problem on re-collection thread using join
by BrowserUk (Patriarch) on Dec 01, 2004 at 18:21 UTC | |
|
Re: The problem on re-collection thread using join
by zentara (Cardinal) on Dec 02, 2004 at 13:57 UTC |