Why main didn't wait until testfun finished in my example below? It seems is_joinable returned false. I found "a call to is_joinable returns true only if a thread has finished running, hasn't been detached and hasn't been joined already". How to judge a running but not join thread?
Hi, Anonymous Monk, I changed my code as below. If I have requirement to judge before join...how to write the condition...
#/usr/bin/perl -w use strict; use warnings; use threads; my @arrayRunningThreads = (); &main; sub main { my $thrHandle = threads->create(\&detachedThreads); $thrHandle->detach(); push @arrayRunningThreads, $thrHandle; for(1...3){ $thrHandle = threads->create(\&MustJoin); push @arrayRunningThreads, $thrHandle; } foreach (@arrayRunningThreads){ $_->join() if( $_->is_joinable() ); } print "End. \n"; } sub detachedThreads { sleep 3; print "exiting thread.\n"; } sub MustJoin { sleep 3; print "exiting thread.\n"; }
output: End. Perl exited with active threads: 3 running and unjoined 0 finished and unjoined 1 running and detached
In reply to is_joinable question by anaconda_wly
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |