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

    Joined:
    Jul 30, 2008
    #1
    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"
    }
     
  2. mfram macrumors 65816

    Joined:
    Jan 23, 2010
    Location:
    San Diego, CA USA
    #2
    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