1)

use strict; use warnings; use 5.012; use threads; use Thread::Queue; my $q = Thread::Queue->new; sub do_stuff { my $id = threads->tid; my $data; while ($data = $q->dequeue) { #Process data: sleep rand(5); say "$id: Done with: '$data'. ", 'Going back to q to get more data.'; } say "$id: No more data in q. Quitting..."; } my $max_threads = 5; my @threads = map { threads->create(\&do_stuff) } 1 .. $max_threads ; #All threads are now blocking on dequeue() and waiting for data. my @data = qw( hi hello greetings what where how world earth gia mars venus jupiter ); for my $data (@data) { $q->enqueue($data); } #Make all threads exit their while loops: for (1 .. $max_threads) { $q->enqueue(undef); } #Don't end the program until all threads have finished: for my $thr (@threads) { $thr->join } --output:-- 1: Done with: 'greetings'. Going back to q to get more data. 5: Done with: 'hello'. Going back to q to get more data. 3: Done with: 'what'. Going back to q to get more data. 5: Done with: 'world'. Going back to q to get more data. 5: Done with: 'earth'. Going back to q to get more data. 4: Done with: 'how'. Going back to q to get more data. 2: Done with: 'hi'. Going back to q to get more data. 1: Done with: 'where'. Going back to q to get more data. 1: No more data in q. Quitting... 5: Done with: 'mars'. Going back to q to get more data. 5: No more data in q. Quitting... 3: Done with: 'gia'. Going back to q to get more data. 3: No more data in q. Quitting... 4: Done with: 'venus'. Going back to q to get more data. 4: No more data in q. Quitting... 2: Done with: 'jupiter'. Going back to q to get more data. 2: No more data in q. Quitting...

In reply to Re: Reaped: beginner:pls finished the multiple thread port scanner scripts by 7stud
in thread Reaped: beginner:pls finished the multiple thread port scanner scripts by NodeReaper

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.