You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Aleric Inglewood <al...@gmail.com> on 2009/07/15 13:09:16 UTC

Is apr_pool_t thread-safe?

Hiya,

I'm working on the Second Life viewer, and I noted a threads related
problem with
the memory pool management.

Now we have to decide whether to use one APR memory pool per thread or,
to allow multiple thread to use the same apr_pool_t undercertain circumstances.

I cannot find the answer to my question in the documentation;
is apr_pool_t thread safe, and if so, what precautions are needed to
make it so?

Is there any disadvantage in using the apr_pool_t by different threads?

Thanks,
Aleric

Re: Is apr_pool_t thread-safe?

Posted by Sander Striker <st...@apache.org>.
On Thu, Jul 16, 2009 at 3:13 AM, Neil Conway<nr...@cs.berkeley.edu> wrote:
> On Wed, Jul 15, 2009 at 4:42 PM, Bojan Smojver<bo...@rexursive.com> wrote:
>> Pools are explicitly thread unsafe, so if you you are doing something to
>> the same pool from two different threads, you must synchronise using
>> your own mutex.
>
> ... except for creating subpools, which is a thread-safe operation.

...if the allocator of the pool the subpool is created on actually has a mutex.

> Neil

Cheers,

Sander

Re: Is apr_pool_t thread-safe?

Posted by Neil Conway <nr...@cs.berkeley.edu>.
On Wed, Jul 15, 2009 at 4:42 PM, Bojan Smojver<bo...@rexursive.com> wrote:
> Pools are explicitly thread unsafe, so if you you are doing something to
> the same pool from two different threads, you must synchronise using
> your own mutex.

... except for creating subpools, which is a thread-safe operation.

Neil

Re: Is apr_pool_t thread-safe?

Posted by Bojan Smojver <bo...@rexursive.com>.
On Wed, 2009-07-15 at 13:09 +0200, Aleric Inglewood wrote:

> Now we have to decide whether to use one APR memory pool per thread or,
> to allow multiple thread to use the same apr_pool_t undercertain circumstances.

This is a cut'n'paste of my own reply from an old thread (no other
committer corrected me than, so I guess it still stands):

Pools are explicitly thread unsafe, so if you you are doing something to
the same pool from two different threads, you must synchronise using
your own mutex.

-- 
Bojan


Re: Is apr_pool_t thread-safe?

Posted by Dan Poirier <po...@pobox.com>.
Aleric Inglewood <al...@gmail.com> writes:

> I cannot find the answer to my question in the documentation;
> is apr_pool_t thread safe, and if so, what precautions are needed to
> make it so?

Looking at APR 1.3.4, it appears apr_pool_t is not thread safe.  Pools
have a mutex, but it's only used by some of the debugging functions.  So
you'd want to be sure not to access a pool from different threads at the
same time.

-- 
Dan Poirier <po...@pobox.com>