Why doesn't Perl threading work when I call readdir beforehand?

Posted by Kevin on Stack Overflow See other posts from Stack Overflow or by Kevin
Published on 2010-12-26T03:47:13Z Indexed on 2010/12/26 3:54 UTC
Read the original article Hit count: 244

Filed under:
|
|

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" }

© Stack Overflow or respective owner

Related posts about multithreading

Related posts about perl