develooper Front page | perl.perl5.porters | Postings from September 2010

[perl #77622] fork crashes perl on windows

Thread Previous
From:
Alexandr Ciornii via RT
Date:
September 1, 2010 10:56
Subject:
[perl #77622] fork crashes perl on windows
Message ID:
rt-3.6.HEAD-5116-1283363800-72.77622-15-0@perl.org
On Wed Sep 01 10:03:57 2010, strop wrote:
> This is a bug report for perl from sinantrop@gmail.com,
> generated with the help of perlbug 1.39 running under perl 5.12.1.
> 
> This program crashes perl on windows with those messages:
> Free to wrong pool 18247e8 not 245a60 at 1.pl line 11.
> Free to wrong pool 1859c50 not 245a60 at 1.pl line 11.
> 
> sub ListDir
> {
>   my ($dir, $proc)=@_;
> 
>   local *DH;
>   opendir(DH,$dir);
>   while(my $fn=readdir(DH))
>   {
>     &$proc($fn, $dir);
>   }
>   closedir(DH);
> }
> 
> ListDir(".", sub
> {
>   my ($fn, $dir)=@_;
>   print "$dir/$fn\n";
> 
>   fork;
> });
> ---

I'm not sure that it is a good idea to mix dirhandles and fork/threads.
This program works correctly:
sub ListDir
{
my ($dir, $proc)=@_;

opendir(my $dh,$dir);
my @files=readdir($dh);
closedir($dh);
foreach my $fn (@files)
{
  $proc->($fn, $dir);
}
}

ListDir(".", sub
{
my ($fn, $dir)=@_;
print "$dir/$fn\n";

fork;
});

It's result are meaningless though - for last file $proc will be
executed 2^N times, where N is numner of files.

-- 
Alexandr Ciornii, http://chorny.net


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About