httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jacob Champion <jacob.champ...@ni.com>
Subject Signal-safe way to start a worker thread in each child process?
Date Tue, 02 Jun 2015 19:15:18 GMT
Hello all,

We're developing an Apache module that requires a background thread to
be running in each individual child process. We've been calling
apr_thread_create() during the child_init hook, and at first that
appeared to work. Then we started seeing intermittent hangs on worker
shutdown.

We found out that our background thread was intercepting signals that
were meant for the main thread. Apparently the apr_setup_signal_thread()
function is meant to prevent this from happening; its documentation
says, "Warning: This must be called before any threads are created."
Unfortunately, mpm_worker calls apr_setup_signal_thread() _after_ it
runs the child_init hooks (see the child_main() implementation in
server/mpm/worker/worker.c), so we're not getting its protection.

We could just call apr_setup_signal_thread() ourselves -- and doing that
does fix the problem -- but that means that modules which are
initialized after us will get the global protection too, which doesn't
feel clean. So, a few questions:

1) Is creating a new thread during the child_init hook the correct way
to ensure that each child process gets its own background thread?

2) If so, is it intended behavior that Apache calls
apr_setup_signal_thread() after the child_init hook, instead of before it?

In case it matters, this is httpd 2.4.10 on Linux. Thanks for your time!

Jacob Champion
LabVIEW R&D
National Instruments

Mime
View raw message