Hi There, Can someone tell me why this is not enqueueing the hashs, and tell me the solution? Here is the code:
#!/usr/bin/perl use warnings; use threads qw[ yield ]; use threads::shared; use Thread::Queue; use Mysql; use constant NTHREADS => $ARGV[1]; $db = Mysql->connect('localhost', 'xxx', 'xxx', 'xxx'); %action = GetActionDetail($ARGV[0]); %userData = GetUserDetail($action{'id_user'}); %companyData = GetCompanyDetail($userData{'id_company'}); my $pos :shared = 0; $sql = "SELECT * FROM v_queue WHERE id=".$ARGV[0]; $query = $db->query($sql); $total = $query->numrows; if ($total>0){ my $Q = Thread::Queue->new; my @threads = map threads->create( \&worker, $Q ), 1 .. NTHREADS; sleep 0.5 while $Q->pending; while (%queueData = $query->fetchhash){ my %item = (); $item{'action'} = $action; $item{'user'} = $userData; $item{'company'} = $companyData; $item{'queueData'} = $queueData; $Q->enqueue( $item ); lock $pos; } $Q->enqueue( (undef) x NTHREADS ); $_->join for @threads; } sub GetActionDetail { my $id = $_[0]; my $sql = "SELECT * FROM `actions` WHERE id='$id'"; my $query = $db->query($sql); my $found = $query->numrows; if ($found==1){ return $query->fetchhash; } else { return "false"; } } sub GetUserDetail { my $id = $_[0]; my $sql = "SELECT * FROM `user` WHERE id='$id'"; my $query = $db->query($sql); my $found = $query->numrows; if ($found==1){ return $query->fetchhash; } else { return "false"; } } sub GetCompanyDetail { my $id = $_[0]; my $sql = "SELECT * FROM `company` WHERE id='$id'"; my $query = $db->query($sql); my $found = $query->numrows; if ($found==1){ return $query->fetchhash; } else { return "false"; } } sub worker { my $Q = shift; my $tid = threads->tid; while( $item = $Q->dequeue ) { print "ITEM ID: ".$item{'action'}{'id'}."\n"; } }

In reply to Threads Enqueue Hashes by NewtonMan

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.