Why doesn't Perl threading work when I call readdir beforehand?
- by Kevin
Whenever I call readdir before I create a thread, I get an error that looks like this:
perl(2820,0x7fff70c33ca0) malloc: * error for object 0x10082e600: pointer being freed was not allocated
* set a breakpoint in malloc_error_break to debug
Abort trap
What's strange is that it happens when I call readdir before I create a thread (i.e. readdir is not called in any concurrent code). I don't even use the results from readdir, just making the call to it seems to screw things up. When I get rid of it, things seem to work fine. Some example code is below:
opendir(DIR, $someDir);
my @allFiles = readdir(DIR);
close(DIR);
my $thread = threads-create(\&sub1);
$thread-join();
sub sub1 {
print "in thread\n"
}