#!/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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|