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

Discussion in 'Mac Programming' started by pacers721, Dec 25, 2010.

  1. pacers721 macrumors member

    Jul 30, 2008
    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);

    my $thread = threads->create(\&sub1);

    sub sub1 {
    print "in thread\n"
  2. mfram macrumors 65816

    Jan 23, 2010
    San Diego, CA USA
    I would try calling "closedir(DIR)" instead of "close(DIR)".

    perldoc -f opendir

    ... it's quite clear about that.

    I reproduced the issue with your code on Linux. And closedir() did indeed fix the issue on my box.

Share This Page