title: Perl Queue and Threads abnormal exit
body: <p>I am quite new to Perl, especially Perl Threads.
  I want to accomplish:</p>
  
  <ol>
  <li>Have 5 threads that will en-queue data(Random numbers) into a
  Thread::queue </li>
  <li>Have 3 threads that will de-queue data from the
  Thread::queue.</li>
  </ol>
  
  <p>The complete code that I wrote in order to achieve above mission:</p>
  
  <pre><code>#!/usr/bin/perl -w
  use strict;
  use threads;
  use Thread::Queue;
  
  
  my $queue = new Thread::Queue();
  our @Enquing_threads;
  our @Dequeuing_threads;
  
  sub buildQueue
  {
      my $TotalEntry=1000;
      while($TotalEntry-- &gt;0)
      {
          my $query = rand(10000);
          $queue-&gt;enqueue($query);
          print "Enque thread with TID " .threads-&gt;tid . " got $query,";
          print "Queue Size: " . $queue-&gt;pending . "\n";
      }
  }
  sub process_Queue 
  {
      my $query;
      while ($query = $queue-&gt;dequeue) 
      {
          print "Dequeu thread with TID " .threads-&gt;tid . " got $query\n";
      }
  }
  push @Enquing_threads,threads-&gt;create(\&amp;buildQueue) for 1..5;
  push @Dequeuing_threads,threads-&gt;create(\&amp;process_Queue) for 1..3;
  </code></pre>
  
  <p><strong>Issues that I am Facing</strong>:</p>
  
  <ul>
  <li>The threads are not running as  concurrently as expected.</li>
  <li>The entire program abnormally exit with following  console output: </li>
  </ul>
  
  <blockquote>
    <p>Perl exited with active threads:
            8 running and unjoined</p>
  
  <pre><code>    0 finished and unjoined
      0 running and detached
  
      Enque thread with TID 5 got 6646.13585023883,Queue Size: 595 
      Enque thread with TID 1 got 3573.84104215917,Queue Size: 595
  </code></pre>
  </blockquote>
  
  <p>Any help on code-optimization is appreciated.</p>