in reply to Re: cgi thread creation segfault
in thread cgi thread creation segfault

In other words, Apache - at least the MPM you're using (prefork?) - doesn't seem to be thread-safe.

<speculation>I would suppose prefork to be able to run this kind of script or at least pose the least problems, while any threaded MPMs will likely (and obviously do) become very confused if some other component such as Perl starts fiddling with the thread pool created by any of their processes.</speculation>

Replies are listed 'Best First'.
Re^3: cgi thread creation segfault
by lelotto85 (Initiate) on Dec 28, 2011 at 19:33 UTC
    I'm a bit confused... @mbethke, are you telling me that I should try with MPM prefork?

    I've been scraping the apache documentation for days and I found about MPM prefork: It is appropriate for sites that need to avoid threading for compatibility with non-thread-safe libraries So I thought this could not be the best approach. Otherwise I didn't understand how can I make a multi-threaded perl script working under Apache... Any help is welcome even if this could not be the correct place to post this request... Thank you very much.

      lelotto85, the way I read this MPM-prefork doc snippet is that prefork is the appropriate multiprocessing mode if you want to run an Apache module that is itself not thread safe, stuff like *cough*mod_php*cough*. These modules fail if they are entered by multiple threads at the same time, e.g. because they use module-global variables, so Apache plays it safe with MPM-prefork and simply forks a new process for each connection handler. That doesn't mean that modules that are in fact able to use threads can't use them in the context of this process, think (as I said that's speculation because I haven't tried) it's rather the opposite: if Apache doesn't manage its own threading, you're least likely to screw it up when you create your own threads. May be worth trying.

      That said, are you sure you need threads in your CGI? Depending on what other content or even other sites your Apache serves MPM-prefork can perform worse than other modules, especially on slow forkers like Solaris or Windows. Frameworks like Coro or POE could save you some headaches (although the latter may bring its own performance problems by being rather fat) by using cooperative multitasking that lets you have virtual threads without real multiprocessing. A sensibly loaded web server will make use of multiple CPUs anyway by using them to handle distinct connections.

        That said, are you sure you need threads in your CGI?

        I do not need threads... It was a way to get the execution faster and fulfill the web request in less time!
        Maybe this isn't the best approach but is an opportunity (for me) to learn something new! :P

      Finally got it!!!

      My error was in apache configuration... I had:

      SetHandler perl-script

      Instead of:

      SetHandler modperl

      Thanks for your support! ;P