Hello.

I'm writting multi-threaded event-driven scgi server using APR.
I've met some strange issues with apr_pool_destroy() function.

The programm works as follows:
1. main() function creates root memory pool and several threads.
2. Each thread has it's own pool created from common parent at point 1.
3. Listening socket is shared between threads. accept() is locked with mutex.
4. Each thread is running event loop using apr_poll functions.
5. For each request handled by the server a new memory pool is created. The parent of this pool is thread pool. (from point 2).
6. When request completes, request pool is destroyed.

When number of threads is greater than 1 and high concurency issued while tests (100 or more concurent connections, about 7000 r/s) i'm observing unpredictable behaviour such as segfaults or callback function looping.

Two workarounds were found empirically:

1. Lock all threads before calling apr_pool_destroy() that destroys request pool; Release lock after. 2. Do not use parent memory pool (from point 1) while creating thread pools (at point 2). In other words - create root memory pool in each thread.

The question is:
Is apr_pool_destroy() fully thread-safe?


Reply via email to