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__
In reply to The problem on re-collection thread using join by RobCheung
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |