Mike Zelina wrote:
This sounds like the reason why Apache::DProf won't work for me
on Win32... I did get it to not crash in mp2 by changing output
to use PerlIO, but it never created any output in the tmon.out file.
Since DProf uses PerlChildInitHandlers, and win32 doesn't support
that even in mp2, I guess I'm hosed (apart from booting to Linux
of course!). Are there any events that get thrown when a new thread
is spawned that I can catch within DProf to make it work on all
platforms??
I think PerlChildInitHandler works just fine under win32, however it's called
only once when the only process starts. I haven't verified that though, since
I don't run win32. In any case that doesn't matter since Apache::DProf needs
to be attached to a perl interpreter. So in the forked environment, child_init
will do the work as before, in the threaded enviroment we can use the special
CLONE block to make things happen on when an interpreter is perl_clone()'d.
perlmod says:
Ithreads work by cloning the data tree so that no data is shared
between different threads. These threads can be used using the threads
module or by doing fork() on win32 (fake fork() support). When a thread
is cloned all Perl data is cloned, however non-Perl data cannot be
cloned automatically. Perl after 5.7.2 has support for the "CLONE"
special subroutine . In "CLONE" you can do whatever you need to do,
like for example handle the cloning of non-Perl data, if necessary.
"CLONE" will be executed once for every package that has it defined (or
inherits it). It will be called in the context of the new thread, so
all modifications are made in the new area.
Here is a quick command line example:
use constant THREADS => eval {require threads };
if (THREADS) {
sub CLONE {warn "I was cloned\n"; }
threads->new(sub {})->detach;
}
under mod_perl that would probably be something like this:
if (Apache::MPM_IS_THREADED) {
sub CLONE {warn "I was cloned\n"; on_init() }
}
else {
require Apache::RequestUtil;
Apache->push_handlers(PerlChildInitHandler => \&on_init);
}
sub on_init { ... }
However I think that 'require threads' might still be needed if CLONE is
implemented by threads.xs and not core perl.
This is untested but probably in the right direction.
Once we have a working prototype, I think we should package the if/else into a
new single directive, to make things work disregarding whether the mpm is
threaded or not.
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@xxxxxxxxxx http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
|