Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: is_joinable question

by Anonymous Monk
on Jun 05, 2013 at 06:50 UTC ( [id://1037140]=note: print w/replies, xml ) Need Help??


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; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1037140]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-23 16:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found