in reply to Re^3: Why isn't this code thread-safe? (MCE!)
in thread Why isn't this code thread-safe? (Is "require" thread-safe??)

So, the problem is not about Compress::Zlib (or poor Text::PDF::Filter... did we torture it beyond convalescing? oops, sorry). The minimal script is then:

use strict; use warnings; use feature 'say'; use threads; use Thread::Queue; my $q = Thread::Queue-> new; my @gang = map async( sub { while ( defined( my $f = $q-> dequeue )) { require IO::Handle; say threads-> tid; } }), 1 .. 8; $q-> enqueue( $_ ) for 1 .. @gang; $q-> end; $_-> join for @gang;

which sometimes (often, both Windows and Linux) fails randomly. Further, replacing the require line with

use XSLoader; XSLoader::load 'IO';

sometimes there are strange warnings, like:

Constant subroutine SEEK_END redefined at threads.pl line 4294967295

Maybe this line number ("broken source"?) is important, maybe not. Until (if ever) the issue is fixed, maybe it would be good idea to advise (documentation, i.e.) to use IO:Handle in any threaded code? Won't hurt...

As to issue of "multi-process safe modules", I can't get same problem if above script is simply re-written using fork (Linux), perhaps it's unrelated issue?

And, certainly, thanks for showing that even a throw-away, few dozen lines script is as easily written using MCE, as "vanilla Perl", except it "just works", because author has put his knowledge and effort to take care of possible bugs. Thanks, Mario :)