httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joseph Chen <joseph.yx.c...@gmail.com>
Subject Re: Function for child_init_hook being called more than one times?
Date Mon, 14 Dec 2009 09:00:19 GMT
On Mon, Dec 14, 2009 at 1:16 AM, Ruediger Pluem <rpluem@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

Mime
View raw message