Hi I am having problems with the following code...this fails with any thing beyond 9 @stores.. I am not able to understand the current available Thread::Queue documentation to make sense of whats going on.... Any help is appreciated... Thanks
#!/opt/perl-5.8.8/bin/perl -w # # use strict; use Getopt::Long; use threads; use threads::shared; use Thread::Queue; require Data::Dumper; my $max_thread_count = 10; my $version = "0.1_01"; my @stores = sort map { sprintf 'store%03d', $_ } 0..$max_thread_count +; my $thread; my $thread_list; my $tid; sub writeLog { print "$_[0]\n"; } my $jobs = Thread::Queue->new(@stores); # read work file sub processWF { my @lines = ( 'perl -wle "print q(storeplaceholder stage 1);sleep(rand(10));pr +int q(storeplaceholder stage 1 done)"', 'perl -wle "print q(storeplaceholder stage 2);sleep(rand(10));pr +int q(storeplaceholder stage 2 done)"', ); while (defined (my $item = $jobs->dequeue)) { writeLog("Launching $item"); foreach my $line (@lines) { print "replacing $line with $item\n"; $line =~ s/storeplaceholder/$item/g; #print "running: $line\n"; system($line) == 0 or warn "Couldn't launch $line: $!"; } } } $jobs->enqueue(undef) for 1..$max_thread_count; my @workers = map { threads->create( \&processWF ) } 1..$max_thread_co +unt; $_->join() for @workers;

In reply to Problem with threading code by theknightsofni

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.