Hello,

I am having a strange concurrency issue with Thread::Queue. Specifically, in some code that uses threads, the program runs for a time, but eventually all threads are put to sleep. The goal of my program is to read lines from text file A, have each thread perform an operation on a line using another text file B, and then write each result to another text file C. Here is a description of the threads:

My problem is that somehow the 5 workers become blocked, which blocks the main process (since there are no workers to work) and then the writer thread (since there are no results to write). The code for the workers looks as follows:

use threads; use threads::shared; use Thread::Queue; ... my $thr = threads->create( sub { my $threadId = $i; open my $REFERENCE_FILE, '<', "$refFileName" or die "Can't open $refFileName: $!"; while ( defined( my $item = $inQ->dequeue() ) ) { # get info from the current item my $lot = $item->{ 'lot' }; my $batch = $item->{ 'batch' }; my $part = $item->{ 'part' }; ... # perform an operation on the item ... my %result = ( 'lot' => $lot, 'batch' => $batch, 'part' => $part, 'thread' => $threadId, 'extensions' => \@bestSeedExtensions, 'num_mm' => $bestSeedOverallMismatches, 'beadid' => $beadID, 'read' => $readSequence, ); $outQ->enqueue( \%result ); # <------ I AM BROKEN :( } } );# end sub

Using print statements, I've traced the problem to the outQ->enqueue() statement. The strange part is that everything runs fine for millions of lines and then suddenly all progress stops. Can anyone tell me why this might be happening? I have tried both perl v5.8.5 and v5.10.1.


In reply to Tread::Queue enqueue blocks all of my threads by sivert

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.