01-06-10 09.55, skrev Kirill E. Shpitsa p� [EMAIL PROTECTED]
f�ljande:

> Hi!
> 
> Consider the following snippet running on Win32 platform:
> 
> use Win32::Event;
> 
> $event=Win32::Event->new(1,1,'');
> # waitpid((fork() or exit),0);
> print "waiting...";
> $event->wait() or die $^E;
> print "done\n";
> 
> not paying attention to it being absolutely useless, it runs as expected:
> 
> waiting...done
> 
> However, if you uncomment the "waitpid..." line (which just creates another
> thread (on my perl) which immediately exits, and, in main thread, waits for
> termination of that new thread) I start getting the following:
> 
> waiting...The handle is invalid at b.pl line 6.
> 
> The apparent reason for such behavior is that $event variable gets cloned
> into new pseudo-process (read:"thread") and upon its termination,
> $event::DESTROY gets called, closing the Win32 event handle.
> 
> (Same happens with other Win32 specific modules, that use non-file handles.
> At first, I came upon it using Win32::API that allows loading and calling
> arbitrary dlls without need to write an XS. After the first fork, any call
> to dll functions would cause page faults...)
> 
> It appears to me, that a correct solution would be to have an implicitly
> called method CLONED (or like) which would allow object needing it adjust
> themselves to "the new environment". I believe that it might be useful under
> both Win32 and Unix platforms.
> 
> Meanwhile, can you offer a solution that would not require getting a new
> version of Perl...
> 
> ----------------------------------------------------------------------------

Thanks for the bug report.

I am not sure this has anything to do with pseudo fork, rather with fork
semantics. (On unix you will have the same problem if you fork a DBI handler
for example).

If Win32::Event objects (the underlaying win32 thingy) should be shared
across forks then I don't see how CLONE is going to help. If it is supposed
to be cloned, the new perl 5.7.2 coming soon has a CLONE method callback, it
will call all packages CLONE if they have that defined on a pseudo fork.
This will allow you to duplicate the Event Handle. CLONE will never be
called for real forking.

A simple solution is to rebless the object into another package, or do an
unclean shutdown using POSIX::_exit(0) or kill 9,$$; from the child, thus
avioiding global destruction of that interpreter. I don't know if this is
possible under pseudo forking.

What perl realy needs is an at_fork() style module that lets special fork
specific behaviour be implmented. This has been discussed between me and
Jenda Krynicky on the [EMAIL PROTECTED], including a test
implmentation. 

Artur

Reply via email to