[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

RE: [BUG] Mutex is destroyed when clearing top level pool, WAS: RE: svn commit: rev 2017 - trunk/subversion/libsvn_subr

From: Sander Striker <striker_at_apache.org>
Date: 2002-05-30 01:36:53 CEST

> From: Philip Martin
> Sent: 29 May 2002 23:30

[...]
> If you really want to go down the destroy/recreate route I think you
> need something like
>
> if pool has parent
> lock parent's mutex
> remove pool from parent's list
> unlock parent's mutex
> endif
> clear pool
> recreate pool's mutex
> if pool has parent
> lock parent's mutex
> add pool to parent's list
> unlock parent's mutex
> endif
>
> That, as far as I can see, is thread-safe and doesn't have the
> potentially unbounded memory problem. The unlock while clearing the
> pool is optional, you could hold the parent's lock for the whole
> operation.

How's this for an alternative?

Sander

Index: memory/unix/apr_pools.c
===================================================================
RCS file: /home/cvs/apr/memory/unix/apr_pools.c,v
retrieving revision 1.170
diff -u -r1.170 apr_pools.c
--- memory/unix/apr_pools.c 29 May 2002 23:02:24 -0000 1.170
+++ memory/unix/apr_pools.c 29 May 2002 23:22:41 -0000
@@ -1382,13 +1382,44 @@
 APR_DECLARE(void) apr_pool_clear_debug(apr_pool_t *pool,
                                        const char *file_line)
 {
+#if APR_HAS_THREADS
+ apr_thread_mutex_t *mutex = NULL;
+#endif
+
     apr_pool_check_integrity(pool);

 #if (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE)
     apr_pool_log_event(pool, "CLEAR", file_line, 1);
 #endif /* (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE) */

+#if APR_HAS_THREADS
+ if (pool->parent != NULL)
+ mutex = pool->parent->mutex;
+
+ /* Lock the parent mutex before clearing so that if we have our
+ * own mutex it won't be accessed by apr_pool_walk_tree after
+ * it has been destroyed.
+ */
+ if (mutex != NULL && mutex != pool->mutex) {
+ apr_thread_mutex_lock(mutex);
+ }
+#endif
+
     pool_clear_debug(pool, file_line);
+
+#if APR_HAS_THREADS
+ /* If we had our own mutex, it will have been destroyed by
+ * the registered cleanups. Recreate the mutex. Unlock
+ * the mutex we obtained above.
+ */
+ if (mutex != pool->mutex) {
+ (void)apr_thread_mutex_create(&pool->mutex,
+ APR_THREAD_MUTEX_NESTED, pool);
+
+ if (mutex != NULL)
+ (void)apr_thread_mutex_unlock(mutex);
+ }
+#endif /* APR_HAS_THREADS */
 }

 APR_DECLARE(void) apr_pool_destroy_debug(apr_pool_t *pool,

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sat Jun 1 14:22:44 2002

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.