Added some comments to help you out:

use 5.16.2; use threads; use Thread::Queue; my @serverList = qw(one two three four five six); # Array to hold list + of servers that need to be updated my $serverQueue = Thread::Queue->new( @serverList ); # Create a Thread +::Queue, passing in the array of servers as items to queue (each serv +er is queued as a single string) $serverQueue->end; # Nothing else will be queued, so notify the queue +of this by ending it my @threads = map { threads->new( \&worker ) } 1..4; # Create a suitab +le number of threads that wont overload IO on the local server $_->join for @threads; # Block here until all the threads have complet +ed say 'Back to main - Finished!'; # End of program sub worker { my $tid = threads->tid; # Get the ID number of the thread while ( my $server = $serverQueue->dequeue_nb ) { # Dequeue the ne +xt item from the queue, in a non-blocking fashion (will undef and fin +ish loop once the queue is empty) say "I'm thread ID $tid and I'm processing server $server"; sleep 1; } say "Thread ID $tid finished"; }

In reply to Re^5: Queuing in multithread context by SimonPratt
in thread Queuing in multithread context by Hardin

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.