You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Henry Jen <he...@ztune.net> on 2005/05/03 10:00:24 UTC
Re: some questions about thread creation and thread pool
On Wed, 2005-04-27 at 20:09 +0800, Cheng Po-wen wrote:
> Hi,
>
> I try to write a thread pool implementation on top of Apache APR,
> I meet some problems:
>
> 1. apr_thread_create (apr_thread_t **new_thread, ....., apr_pool_t
> *cont)
>
> I've trace the source code about this function,
> internally, it uses "count" to allocate the memory for apr_thread_t,
> & pthread_t
> like :
>
> (*new) = (apr_thread_t *)apr_pcalloc(pool, sizeof(apr_thread_t));
> (*new)->td = (pthread_t *)apr_pcalloc(pool, sizeof(pthread_t));
>
> and it uses "count" as parent pool to create a new pool for this
> thread,
>
> when "child threads" exit, they will automatically destroy their own
> pool,
> but the questions is this will still leave the apr_thread_t, &
> pthread_t
> memory allocated in the parent pool "dangling".
>
Automatically? Correct me if I am wrong, you need to call
apr_thread_exit explicitly within the thread function to destroy the
pool.
>
> so,....
> can I solve the "dangling" memory problem when creating Thread Pool on
> top of APR?
> because threads are created & exit (if nessary) all the time in my
> implementatin.
>
You have to destroy the pool you passed in to create the
thread(parameter cont) to reclaim the memory, I believe.
Cheers,
--
Henry Jen aka slowhog