#!/opt/coolstack/bin/perl use strict; use threads ('yield', 'stack_size' => 64*4096, 'exit' => 'threads_only', 'stringify'); #--------------------------------------------------------------- my $path = "/tmp"; my $time = time; #my @files = qw(detail-1min-19-06-22); my @files = &get_files($path); my @thrs_loaders; foreach my $file (@files){ my ($thr) = threads->create(\&load, $file); push @thrs_loaders, $thr; } $_->join for @thrs_loaders; exit; #--------------------------------------------------------------------- sub get_files{ my $dir = shift; opendir(DIR, $dir) or die "Cant open dir $!"; # HERE IS THE CAUSE close(DIR); return "detail-1min-19-06-22"; } #--------------------------------------------------------------------- sub load{ my $file = shift; print "Processing $file\n"; }
I've tested in:
Any tips?$ perl -Mthreads -e 'print $threads::VERSION' 1.71 $ perl -v This is perl, v5.8.8 built for sun4-solaris-thread-multi
In reply to Threads + opendir = Segmentation Fault (core dumped) by gulden
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |