in reply to is_joinable question
The correct way to write that loop
while( @arrayRunningThreads ){ my @keepers; for my $thread ( @arrayRunningThreads ){ if( $thread->is_joinable() ){ $thread ->join; } elsif( not $thread ->is_detached ){ push @keepers, $thread; } } @arrayRunningThreads = @keepers; }
If you don't add detached threads you can write it as
while( @arrayRunningThreads ){ my @keepers; for my $thread ( @arrayRunningThreads ){ if( $thread->is_joinable() ){ $thread ->join; } else { push @keepers, $thread; } } @arrayRunningThreads = @keepers; }
Or the functional equivalent of what the above code does, relying on the fact that join blocks until a thread is_joinable
for my $thread ( @arrayRunningThreads ){ $thread->join; }
|
|---|