You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by joseph Chen <jo...@gmail.com> on 2009/12/14 09:03:28 UTC
Function for child_init_hook being called more than one times?
Hi,
Can someoen there tell me why my callback routine registred with
"ap_hook_child_init()" is being called multiple times during httpd-2.2
running?
I am a newbie to develope a my own module for apache-2.2. Within my
module, I want to run a new thread for listening a socket port. I
create a new thread within the callback routine for
"ap_hook_chile_init()" but this multiple-calling causes too many
threads being created.
How should I prevent this behavor?
Thanks,
--Joe
Re: Function for child_init_hook being called more than one times?
Posted by joseph Chen <jo...@gmail.com>.
On Mon, Dec 14, 2009 at 1:16 AM, Ruediger Pluem <rp...@apache.org> wrote:
> This hook is called for every child spawned by the main process.
> So if you have multiple client processes (which is very likely) it is
> called multiple times.
>
> Maybe some background information could enable people to provide better help.
Thanks Ruediger for your quick reply. The background info is that I
need to have httpd to spawn a new thread to run my own routine where I
will have socket interface to read data from a port and then to modify
some gloable variables.
Hope you can see my programming logic from following code (to create a
thread to run my routine that just writes log message to my own file):
void* APR_THREAD_FUNC my_listener(apr_thread_t *thread, void *data)
{
my_server_cfg_t *cfg = (my_server_cfg_t *) data;
int i;
for (i = 0;; i++) {
apr_sleep(10);
my_log_to_file( "%s:%s:%d:thread i = %d\n", i);
}
return NULL;
}
static void my_child_init(apr_pool_t *p, server_rec *s)
{
my_server_cfg_t *cfg;
cfg = ap_get_module_config(s->module_config, &my_module);
/* start up ingestor receiver */
/* create a thread */
apr_thread_create(&cfg->listener_thread, NULL, my_listener, (void *)cfg, p);
apr_pool_cleanup_register(p, s, my_child_exit, my_child_exit);
}
And within the "my_register_hooks()", my module code calls:
ap_hook_child_init (my_child_init, NULL, NULL, APR_HOOK_MIDDLE);
When looking at my own log file, I can see the thead was created too many times.
Thanks,
--Joe
Re: Function for child_init_hook being called more than one times?
Posted by Ruediger Pluem <rp...@apache.org>.
On 12/14/2009 09:03 AM, joseph Chen wrote:
> Hi,
>
> Can someoen there tell me why my callback routine registred with
> "ap_hook_child_init()" is being called multiple times during httpd-2.2
> running?
This hook is called for every child spawned by the main process.
So if you have multiple client processes (which is very likely) it is
called multiple times.
>
> I am a newbie to develope a my own module for apache-2.2. Within my
> module, I want to run a new thread for listening a socket port. I
> create a new thread within the callback routine for
> "ap_hook_chile_init()" but this multiple-calling causes too many
> threads being created.
Maybe some background information could enable people to provide better help.
Regards
Rüdiger