#!/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

In reply to Re^2: Thread parallel execution (joinable) by Anonymous Monk
in thread Thread parallel execution by arunbhargav

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.