in reply to Re: Why isn't this code thread-safe? (MCE!)
in thread Why isn't this code thread-safe? (Is "require" thread-safe??)
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Why isn't this code thread-safe? (MCE!)
by BrowserUk (Patriarch) on Nov 10, 2018 at 13:18 UTC | |
|
Re^3: Why isn't this code thread-safe? (MCE!)
by marioroy (Prior) on Nov 19, 2018 at 22:06 UTC | |
by marioroy (Prior) on Nov 19, 2018 at 22:25 UTC | |
by vr (Curate) on Nov 20, 2018 at 16:48 UTC |