title: perl Thread::Queue not dequeueing all items
body: <p>I'm using perl's <a href="https://metacpan.org/module/Thread::Queue" rel="nofollow">Thread::Queue</a> module to keep a pool of threads busy downloading urls for a simple crawler I am working on. Using <code>Thread::Queue</code>, I enqueue a list of hash references (360, to be exact), where each hash holds information about the individual url:</p>
  
  <pre><code>#set up thread queue
  my $THREADS=30; # Number of threads
  my $url_q = Thread::Queue-&gt;new(); # Work to do
  my $url_arr = urls();
  
  my $count = 0;
  for(@$url_arr) { 
      print "ENQUEUEING $_-&gt;{'url'}\n";
      $url_q-&gt;enqueue($_);
      $count++;
  }
  
  print "COUNT $count\n";
  print "QUEUE COUNT " . $url_q-&gt;pending() . "\n";
  
  threads-&gt;create( sub { 
              while(my $url_h = $url_q-&gt;dequeue()) { 
                  print "url: $url_h-&gt;{'url'}\n\n";
                  print "PENDING: " . $url_q-&gt;pending() . "\n";
                  process_url($url_h);
              }
          }) for (1..$THREADS);   
  
  $url_q-&gt;end;
  print "WAITING\n";
  $_-&gt;join() for threads-&gt;list;
  print "DONE WAITING\n";
  </code></pre>
  
  <p>The problem is that I see all 360 urls be enqueued, but then I only ever see the pending number drop down to around 260, meaning that only about 100 really get evaluated and 260 never do? Is there something wrong I'm doing with Thread::Queue? Thanks!</p>