httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gregor Melhorn <>
Subject Segfault creating detached thread in module
Date Thu, 12 Oct 2006 12:31:12 GMT
Hi all,

I've got a problem with creating a detached thread in the post init hook.

static void register_hooks(apr_pool_t *p) {
    ap_hook_post_config(spread_init, NULL, NULL, APR_HOOK_MIDDLE);

void* APR_THREAD_FUNC doit(apr_thread_t *thd, void *data){
	server_rec *s = (server_rec *) data;
	ap_log_error(APLOG_MARK, SPREAD_DEBUG, 0, s, "%s", "running thread" );
	apr_thread_exit(thd, APR_SUCCESS);
    return NULL;

static int spread_init (apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s){
    apr_status_t rv;
    apr_thread_t *thd;
    apr_threadattr_t *thd_attr;
    apr_threadattr_create(&thd_attr, p);
    apr_threadattr_detach_set(thd_attr, 1);
    apr_thread_create(&thd, thd_attr, doit, s, p);
    // rv = apr_thread_join(&rv, thd);
  return DECLINED;

This code just segfaults on starting the server. Omitting the thread attribute(setting the
second param of apr_thread_create to NULL) and uncommenting the join line works fine and writes
to the log (twice!?), but is obviously not what I want.

I want to create a seperate thread in the server that is fetching messages from the spread
daemon (secret keys) and writes them to a shared memory area.

Hope someone can help me out.

Best regards
Gregor Melhorn

Viren-Scan für Ihren PC! Jetzt für jeden. Sofort, online und kostenlos.
Gleich testen!

View raw message