Bug 51392 - apr_pool_t thread-safe pool creation
Summary: apr_pool_t thread-safe pool creation
Status: NEW
Alias: None
Product: APR
Classification: Unclassified
Component: APR (show other bugs)
Version: 1.4.5
Hardware: PC Linux
: P2 enhancement (vote)
Target Milestone: ---
Assignee: Apache Portable Runtime bugs mailinglist
URL:
Keywords: PatchAvailable
Depends on:
Blocks:
 
Reported: 2011-06-17 11:02 UTC by bugzilla
Modified: 2011-06-17 11:02 UTC (History)
0 users



Attachments
Patches apr_pools.c and apr_pools.h to add thread-safe pools (11.15 KB, patch)
2011-06-17 11:02 UTC, bugzilla
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.