apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Konstantin Sharenkov" <Konstantin.Sharen...@enterra-inc.com>
Subject apr_thread_exit destroys parent pool
Date Wed, 10 Jan 2007 09:05:29 GMT
Hello Everyone
 
I think apr_thread_exit function is not usable now, as it destrys parent
pool of the thread

Let me explain: (listinds bellow based on unix version, other platforms
also affected)
I want to finish my threads with some return codes, apr_thread_exit
function is designed for it as I see.

APR_DECLARE(apr_status_t) apr_thread_exit(apr_thread_t *thd,
                                          apr_status_t retval)
{
    thd->exitval = retval;
    apr_pool_destroy(thd->pool); // !!!! DESTROY PARENT POOL
    pthread_exit(NULL);
    return APR_SUCCESS;
}

So thd->pool is parent pool of thread
There is the code of creation:
APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new,
                                            apr_threadattr_t *attr,
                                            apr_thread_start_t func,
                                            void *data,
                                            apr_pool_t *pool)
{
...
    (*new) = (apr_thread_t *)apr_pcalloc(pool, sizeof(apr_thread_t));
...
    (*new)->pool = pool;
...


The problem is that pool life time is different with thread life time.
It is not need to destroy parent pool with thread
In this case And unecpected cleanup of objects from pool will be called,
and pool object referenced by calling program will be also destroyed
unexpeced.

---------------------------------------------------------------------
For example several threads may be in the same pool
Code from tests:
    s0 = apr_thread_create(&p1, NULL, thread_cond_producer, &count1, p);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, s0);
    s1 = apr_thread_create(&p2, NULL, thread_cond_producer, &count2, p);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, s1);
    s2 = apr_thread_create(&p3, NULL, thread_cond_producer, &count3, p);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, s2);
    s3 = apr_thread_create(&p4, NULL, thread_cond_producer, &count4, p);

Four threads in one pool

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

I Can't see any call of apr_thread_exit in tests.

Can you explain apr_thread_exit if I am wrong?
Any call of this function may cash a program.

I think there is need to remove apr_pool_destroy(thd->pool)  from this
function
Or remove this function from APR.

There is previous similar message but not replied:
http://mail-archives.apache.org/mod_mbox/httpd-dev/200402.mbox/%3c423019
046EC9F647AF13F367FB01C158029EC9D1@ftlpexch501%3e


Konstantin Sharenkov
Enterra Inc


Mime
View raw message