title: Attempting to redefine IO::Tee::PRINT for thread safety
body: <p><a href="https://stackoverflow.com/questions/23271659/thread-safe-alternative-to-filetee/23273126?noredirect=1">Thanks to some help</a>, I've started attempting to get thread-safe logging working for my script - however, I don't seem to have it working correctly:</p>
  
  <pre><code>use Fcntl ':flock';
  
  no warnings 'redefine';
  sub IO::Tee::PRINT
  {
      my $self = shift;
      my $ret = 1;
      foreach my $fh (@$self) {
          flock($fh, LOCK_EX);
          print "\n\t\ttestA\n";  #&lt;-- added for testing
          undef $ret unless print $fh @_;
          flock($fh, LOCK_UN);
          print "\t\ttestB\n";    #&lt;-- added for testing
      }
      return $ret;
  }
  
  my $Info_tee = IO::Tee-&gt;new(\*STDOUT, "&gt;$ENV{DOM}\\build.log");
  </code></pre>
  
  <p>When I get to the threaded section of my script:</p>
  
  <pre><code>print $Info_tee "\n------------------------------------------------------\n";
  print $Info_tee "\n\t\t*** Performing Action: \'$cmd\' on $comp ***";
  </code></pre>
  
  <p>My output to <code>STDOUT</code> (4 threads) is:</p>
  
  <pre><code>                testA
                  testA
  
  ------------------------------------------------------
                  testB
  
                  testA
  
  ------------------------------------------------------
                  testB
  
  ------------------------------------------------------
                  testB
  
                  testA
  
                  testA
  
  ------------------------------------------------------
                  testB
  </code></pre>
  
  <p>.. and then the script locks up. What am I doing wrong?</p>
  
  <p><strong>Edit:</strong> I've created a simple example of my issue <a href="https://gist.github.com/anonymous/11263776" rel="nofollow noreferrer">here</a> -- I noticed that if you <a href="https://gist.github.com/anonymous/11269063" rel="nofollow noreferrer">remove the queue</a> from the script, everything seems to work as designed.</p>