stas 2003/12/03 20:50:23
Modified: src/docs/2.0/user/coding coding.pod
Log:
- update the Apache::MPM->is_threaded example
- showcase the new API Apache::MPM->show;
Revision Changes Path
1.28 +30 -5 modperl-docs/src/docs/2.0/user/coding/coding.pod
Index: coding.pod
===================================================================
RCS file: /home/cvs/modperl-docs/src/docs/2.0/user/coding/coding.pod,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -u -r1.27 -r1.28
--- coding.pod 1 Dec 2003 17:56:30 -0000 1.27
+++ coding.pod 4 Dec 2003 04:50:23 -0000 1.28
@@ -74,14 +74,14 @@
=head2 Threaded MPM or not?
If the code needs to behave differently depending on whether it's
-running under one of the threaded MPMs, or not, the
-C<Apache::MPM-E<gt>is_threaded> method can be used. For example:
+running under one of the threaded MPMs, or not, the class method
+C<Apache::MPM-E<gt>is_threaded> can be used. For example:
use Apache::MPM ();
- use APR::OS ();
if (Apache::MPM->is_threaded) {
- my $id = APR::OS::thread_current();
- print "current thread id: $id";
+ require APR::OS;
+ my $tid = APR::OS::thread_current();
+ print "current thread id: $tid (pid: $$)";
}
else {
print "current process id: $$";
@@ -89,6 +89,31 @@
This code prints the current thread id if running under a threaded
MPM, otherwise it prints the process id.
+
+=head2 Writing MPM-specific Code
+
+If you write a CPAN module it's a bad idea to write code that won't
+run under all MPMs, and developers should strive to write a code that
+works with all mpms. However it's perfectly fine to perform different
+things under different mpms.
+
+If you don't develop CPAN modules, it's perfectly fine to develop your
+project to be run under a specific MPM.
+
+ use Apache::MPM ();
+ my $mpm = lc Apache::MPM->show;
+ if ($mpm eq 'prefork') {
+ # prefork-specific code
+ }
+ elsif ($mpm eq 'worker') {
+ # worker-specific code
+ }
+ elsif ($mpm eq 'winnt') {
+ # winnt-specific code
+ }
+ else {
+ # others...
+ }
=head1 Code Developing Nuances
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]