I vaguely recall finding that one of the GZIP modules used some global state

Thanks for answer, I've reduced the problem to Compress::Zlib:

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 Compress::Zlib; say threads-> tid; } }), 1 .. 4; select( undef, undef, undef, 0.1 ) or $q-> enqueue( $_ ) for 1 .. 4; $q-> end; $_-> join for @gang;

With small (or none) delays between threads "requiring" Compress::Zlib, errors are happenning:

D:\>perl test181110.pl 2 3 1 4 D:\>perl test181110.pl 2 4 3 1 D:\>perl test181110.pl 3 2 1 4 D:\>perl test181110.pl String found where operator expected at C:/strawberry-perl-5.28.0.1-32 +bit-PDL/pe rl/lib/IO/Compress/Base/Common.pm line 514, near "croak "$sub: $p->[Ix +Error]"" (Do you need to predeclare croak?) Thread 3 terminated abnormally: syntax error at C:/strawberry-perl-5.2 +8.0.1-32bi t-PDL/perl/lib/IO/Compress/Base/Common.pm line 514, near "croak "$sub: + $p->[IxEr ror]"" BEGIN not safe after errors--compilation aborted at C:/strawberry-perl +-5.28.0.1- 32bit-PDL/perl/lib/IO/Compress/Base/Common.pm line 520. Compilation failed in require at C:/strawberry-perl-5.28.0.1-32bit-PDL +/perl/lib/ Compress/Zlib.pm line 10. BEGIN failed--compilation aborted at C:/strawberry-perl-5.28.0.1-32bit +-PDL/perl/ lib/Compress/Zlib.pm line 10. Compilation failed in require at test181110.pl line 11. 1 4 2 D:\>perl test181110.pl Thread 3 terminated abnormally: Bareword "HIGH" not allowed while "str +ict subs" in use at C:/strawberry-perl-5.28.0.1-32bit-PDL/perl/lib/IO/Compress/B +ase/Common .pm line 868. BEGIN not safe after errors--compilation aborted at C:/strawberry-perl +-5.28.0.1- 32bit-PDL/perl/lib/IO/Compress/Base/Common.pm line 1038. Compilation failed in require at C:/strawberry-perl-5.28.0.1-32bit-PDL +/perl/lib/ Compress/Zlib.pm line 10. BEGIN failed--compilation aborted at C:/strawberry-perl-5.28.0.1-32bit +-PDL/perl/ lib/Compress/Zlib.pm line 10. Compilation failed in require at test181110.pl line 11. 1 2 4 D:\>perl test181110.pl 1 3 1 2 D:\>perl test181110.pl 1 3 2 4

But if delay is increased to 0.3 script is run hundreds of times, with batch command, w/o errors. Instead of delays (value relevant to one PC only), module should be "used" in main thread, of course.

I don't understand why text of errors indicates incomplete or "noisy" reading (parsing) of Perl source files, as if random lines are just omitted. And in OP, same "broken source" happens to rather simple Text::PDF::Filter. As I see, there's relatively complex chain of require's in Text::PDF::Filter, to Compress::Zlib and further to parts of that distribution. Maybe there is same "long chain of requires" in some other distributions, to check with script above?


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

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.