develooper Front page | perl.perl5.porters | Postings from December 2004

Re: [perl #7112] Bug: Win32 fails after 6 forks.

From:
Andrew Savige
Date:
December 3, 2004 02:19
Subject:
Re: [perl #7112] Bug: Win32 fails after 6 forks.
Message ID:
20041202221727.87295.qmail@web50810.mail.yahoo.com
Steve Peters wrote:
>> [Joe.Smith[at]inwap.com - Wed Jun 13 05:18:03 2001]:
>> In reference to a USENET posting.
>> 
>> 		Newsgroups: alt.perl
>> 		Subject: Re: I can not fork at windows
>> 		References: <992330594.302450[at]athnrd02.forthnet.gr>
>> 
>> $|= 1;
>> for $var (1..3)
>> {
>>  for (1..2)
>>  {
>>   if ( $pid=fork() )
>>   {
>>     print "Parent $$ created child $pid\n" ;
>>     sleep 1;
>>     waitpid($pid,0);
>>     exit 0;
>>   }
>>   elsif ( ! defined $pid )
>>   {
>>     die "Can not go to multi thread mode\n"
>>   }
>>   else
>>   {
>>     print "Child $$ running\n";
>>   }
>>  }
>>  print "\nThread team $var finished\n\n";
>> }
>> print "Program $$ finished\n";
>
> I was able to replicate the failure with ActiveState Perl 5.8.4 Build
> 810 on Windows XP.  Although I didn't get the nice failure above, it
> did complain loudly in a popup about writing to a null pointer.

This test program given also crashes the latest Perl 5.8.6.

I was able to get rid of the crashes by replacing:
  for (1..2)
above with:
  for my $z (1..2)
For more variety, if you add:
  local $% = 0;
as the first statement inside each loop, it not only crashes but
generates some:
  Atttempt to free unreferenced scalar
warnings for good measure.

I'm guessing that a localized built-in variable inside the inner loop
will be freed twice at end of scope: once by the original interpreter
and once by the cloned one.

I can't think of a way to simulate the above crash on Linux with plain
old ithreads; if you think of a way, please let me know. Maybe the
scenario above is impossible with plain ithreads?

/-\


Find local movie times and trailers on Yahoo! Movies.
http://au.movies.yahoo.com



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