llancet has asked for the wisdom of the Perl Monks concerning the following question:
In the ActivePerl distribution, there is a method called "is_joinable" to judge whether a thread is completed and can be joined immediately.use threads;
use threads; use threads::shared; my %thread_state:shared; # ignore the creation of threads # a loop that collects all threads while (1) { foreach (threads->list()) { if ($thread_state{$_->tid} eq 'finished') {$_->join;} } sleep 1; last if (&all_finished); } # the thread body looks like this sub thread_body{ # do something # when finished, mark itself { lock %thread_state; $thread_state{$threads->tid} = 'finished'; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how to estimate thread state
by ikegami (Patriarch) on Sep 18, 2008 at 03:20 UTC | |
|
Re: how to estimate thread state
by BrowserUk (Patriarch) on Sep 18, 2008 at 08:57 UTC |