This was a bug in perl, I has been fixed in 5.18.2.
Perl crash: Wrong use of glob in threads?
-
21-07-2023 - |
Question
The following script crashes in perl 5.16. Is there anything wrong with using glob()
in threads?
use strict;
use warnings;
use 5.010;
use threads;
sub f {
my $no = shift;
my @arr = glob("*");
say "thread $no: ", scalar(@arr);
}
foreach my $tno (1..5) {
my $thr = threads->create(\&f, $tno);
$thr->join();
}
It prints
thread 1: 33
and then crashes with a segmentation fault (MacOS) or access violation (Windows 7).
Tested with v5.16.2 on Mac OSX (darwin-thread-multi-2level)
and ActivePerl on Windows 7 64bit (v5.16.3 built for MSWin32-x86-multi-thread)
.
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow