Bug 51392

Summary: apr_pool_t thread-safe pool creation
Product: APR Reporter: bugzilla
Component: APRAssignee: Apache Portable Runtime bugs mailinglist <bugs>
Status: NEW ---    
Severity: enhancement Keywords: PatchAvailable
Priority: P2    
Version: 1.4.5   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Attachments: Patches apr_pools.c and apr_pools.h to add thread-safe pools

Description bugzilla 2011-06-17 11:02:35 UTC
Created attachment 27169 [details]
Patches apr_pools.c and apr_pools.h to add thread-safe pools

There are times that I want to use a data structure across multiple threads, adding to it if necessary. Not in Apache Web Server, but in dedicated projects that use the APR library.

I have proposed to add the apr_pool_create_threadsafe and (_ex and _ex_debug functions) which set a boolean flag in apr_pool_t to indicate that allocations should be protected by the pool's mutex.

Consider the situation where you create two apr_hash_t variables, and then spawn off n threads to process a CPU intensive operation, each thread updating the two variables as they see fit (appropriately locking each one as it is accessed). If the two hashes are from the same pool it is possible they could corrupt the pool if grown at the same time.

Also stopped apr_pool_check_integrity() from complaining if a thread-safe pool is not owned by current thread (in fact, it shouldn't complain at all when creating pools because pool creation is thread-safe anyway).

Untested - but should give a taste for others should they wish to have such functionality.