You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by Gregor Melhorn <g....@web.de> on 2006/10/12 14:31:12 UTC

Segfault creating detached thread in module

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! http://www.pc-sicherheit.web.de/freescan/?mc=022222