You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Sergey Safarov <s....@gmail.com> on 2017/01/15 20:16:13 UTC

thread-saftey memory pools

Could you help me understand why not used mutex to implement thread safety
functions:

   1. apr_palloc
   2. apr_pool_clear
   3. apr_pool_destroy
   4. apr_pvsprintf


In this functions is used:

   1. pool_concurrency_set_used
   2. pool_concurrency_set_idle
   3. pool_concurrency_set_destroyed

And if concurrency access is detected then called "pool_concurrency_abort"
and program terminated.

https://github.com/apache/apr/blob/trunk/memory/unix/apr_pools.c

Re: thread-saftey memory pools

Posted by William A Rowe Jr <wr...@rowe-clan.net>.
The reason is that each thread can obtain its own distinct and therefore
safe allocator.

The model is such that when the thread for finishes a unit of work, it
returns the memory to the thread's allocator for the next unit of work.

The alternative is the malloc/free model which you are used to, which has
performance penalties for allocating from a common and therefore
contested/mutexed resource.

Hope this explanation is helpful. We can and should do a better job of
documenting such, Nick may have a chapter in his APR book on the subject.

On Jan 15, 2017 14:16, "Sergey Safarov" <s....@gmail.com> wrote:

Could you help me understand why not used mutex to implement thread safety
functions:

   1. apr_palloc
   2. apr_pool_clear
   3. apr_pool_destroy
   4. apr_pvsprintf


In this functions is used:

   1. pool_concurrency_set_used
   2. pool_concurrency_set_idle
   3. pool_concurrency_set_destroyed

And if concurrency access is detected then called "pool_concurrency_abort"
and program terminated.

https://github.com/apache/apr/blob/trunk/memory/unix/apr_pools.c