Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: Thread parallel execution (joinable)

by Anonymous Monk
on May 08, 2013 at 02:26 UTC ( #1032561=note: print w/ replies, xml ) Need Help??


in reply to Re: Thread parallel execution (join blocks)
in thread Thread parallel execution

#!/usr/boin/perl -- use strict; use warnings; use threads; for my $ix ( 0 .. 20 ) { threads->create( sub { sleep rand $ix; print join ' ', $$, ix => $ix, tid => threads->tid(), "\n" +; } ); } exit if @ARGV; while( threads->list ) { for my $joinable ( threads->list( threads::joinable ) ) { $joinable->join; } } __END__ $ perl fudge exit 1044 ix 0 tid 1 1044 ix 1 tid 2 1044 ix 2 tid 3 1044 ix 4 tid 5 1044 ix 17 tid 18 Perl exited with active threads: 16 running and unjoined 5 finished and unjoined 0 running and detached $ perl fudge 1948 ix 0 tid 1 1948 ix 1 tid 2 1948 ix 2 tid 3 1948 ix 3 tid 4 1948 ix 4 tid 5 1948 ix 7 tid 8 1948 ix 17 tid 18 1948 ix 9 tid 10 1948 ix 12 tid 13 1948 ix 13 tid 14 1948 ix 18 tid 19 1948 ix 6 tid 7 1948 ix 5 tid 6 1948 ix 10 tid 11 1948 ix 8 tid 9 1948 ix 14 tid 15 1948 ix 19 tid 20 1948 ix 11 tid 12 1948 ix 15 tid 16 1948 ix 16 tid 17 1948 ix 20 tid 21


Comment on Re^2: Thread parallel execution (joinable)
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2014-10-22 00:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (112 votes), past polls