httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gregor Melhorn <g.melh...@web.de>
Subject Re: Segfault creating detached thread in module
Date Thu, 12 Oct 2006 15:04:07 GMT
UPDATE:

It very likely is a memory management bug. I found out I can create a detached thread without
problems, if it is finished before the init function exits! Running the code below works if
sleep(1) in doit() is commented out. Else it segfaults immediately.

Any guesses on what to change on my memory pools so the memory mgmt problem is solved?

Best regards
Gregor

-------------

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, NULL, p);
    sleep(1);
  return DECLINED;
}

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" );
	// sleep(1);
	ap_log_error(APLOG_MARK, SPREAD_DEBUG, 0, s, "%s", "after sleep" );
	apr_thread_exit(thd, APR_SUCCESS);
    return NULL;
}




-----Ursprüngliche Nachricht-----
Von: modules-dev@httpd.apache.org
Gesendet: 12.10.06 14:31:46
An: modules-dev@httpd.apache.org
Betreff: 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



_____________________________________________________________________
Der WEB.DE SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
http://smartsurfer.web.de/?mc=100071&distributionid=000000000066


Mime
View raw message