apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nick Kew <n...@webthing.com>
Subject Re: apr pools with threads
Date Tue, 03 Oct 2006 12:18:55 GMT
On Tuesday 03 October 2006 13:07, Stephen Ciscola wrote:
> Hi,
> I want to use a pool or pools to replace some malloc
> calls in a library i'm working with. I want to avoid
> the constant malloc/free penalty. I intend to just
> toss some defines in to call the pools api whenever
> malloc/free is called.

A good strategy if your pool is (or can be) tied to the natural
lifetime of the resources you're allocating.

> My application is multithreaded. Am I correct that if
> I use pools with an APR I built on linux using
> -enable-threads, that they AREN'T inherently thread
> safe?


> I still need to mutex lock around.... ??? which pool
> calls?

If your pool is shared across threads, yes.  But that would be
an inefficient usage, and could potentially require the vast
majority of APR calls to be mutexed.  Can't you create a
private subpool per thread instead?

> I assume it's fine if I use normal pthread calls, not
> the APR threads model... though I'm free to use either
> really.

I suspect you'll risk losing portability by doing that.

Nick Kew

View raw message