in reply to Threads + opendir = Segmentation Fault (core dumped)

Try this

#! perl use strict; use threads ( 'yield', 'stack_size' => 64*4096, 'exit' => 'threads_only', 'stringify' ); my $path = "/tmp"; my @files = &get_files($path); my @thrs_loaders; foreach my $file (@files){ push @thrs_loaders, threads->create(\&load, $file); } $_->join for @thrs_loaders; <>; exit; sub get_files{ my $dir = shift; opendir(my $dh, $dir) or die "Cant open dir $!"; # HERE IS THE CAUS +E close( $dh); return "detail-1min-19-06-22"; } sub load{ my $file = shift; print "Processing $file\n"; }

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP PCW

Replies are listed 'Best First'.
Re^2: Threads + opendir = Segmentation Fault (core dumped)
by lightoverhead (Pilgrim) on Jun 24, 2009 at 19:23 UTC
    so why "$dh" works but "DH" didn't?

      Good question.

      Probably because there is a latent bug in the cloning of bare word directory handles--but that's speculation.

      With investigation it might be something that could be fixed for the next major release of Perl, but it really doesn't make any sense to not use lexical handles with threads.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
Re^2: Threads + opendir = Segmentation Fault (core dumped)
by gulden (Monk) on Jun 24, 2009 at 17:18 UTC
    Nice tip, it solved my problem!!

    I didn't understand the cause of the problem, but now it works :)