Re: [mp2] threaded applications inside of mod_perl

[prev] [thread] [next] [Date index for 2005/02/04]

From: Stas Bekman
Subject: Re: [mp2] threaded applications inside of mod_perl
Date: 17:28 on 04 Feb 2005
Stas Bekman wrote:
> Thanks for the details. I can now reproduce the segfault. I'll post 
> again when this is fixed.

I've traced it down to a perl-core issue. I'm submitting a report to p5p 
and I've CC'ed you, so you can stay in the loop.

Meanwhile, there are two workarounds:

You must start with not using a tied STDOUT, i.e. change the SetHandler 
setting to 'modperl':

<Directory "/home/nk/www/vhosts/web/apps/">
               SetHandler modperl
               PerlResponseHandler ModPerl::Registry
               PerlOptions +ParseHeaders +GlobalRequest
               Options ExecCGI
</Directory>

now you can either use $r->print(), or tie STDOUT to $r in each thread 
where you want to use it. Do not tie it before starting the threads, since 
you will hit the same problem. The following program demonstrates both 
techniques:

use strict;
use warnings FATAL => 'all';

use threads;

my $r = shift;
$r->print("Content-type: text/plain\n\n");

threads->create(
     sub {
        $r->print("thread 1\n");
     }, undef);

threads->create(
     sub {
         tie *STDOUT, $r;
         print "thread 2\n";
     }, undef);

$r->print("done");

as you use +GlobalRequest you can replace:

my $r = shift;

with

my $r = Apache->request;

but it's a bit slower.



        -- 
        __________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@xxxxxx.xxx http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

(message missing)

[mp2] threaded applications inside of mod_perl
bob-modperl 03:15 on 03 Feb 2005

Re: [mp2] threaded applications inside of mod_perl
Stas Bekman 17:28 on 04 Feb 2005

Generated at 11:21 on 20 Feb 2005 by mariachi v0.52