You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Greg Stein <gs...@lyra.org> on 2002/11/11 02:12:08 UTC

Re: Allocating from a pool in cleanup

On Sun, Nov 10, 2002 at 11:25:59PM +0100, Sander Striker wrote:
>...
> I can confirm that it is safe to do allocations from the pool being cleaned
> up.

Yup. I was looking at this, too, and it is definitely quite safe to do this,
and it really is the only thing that makes sense. A user should never assume
that it can allocate in a parent pool. You could accumulate a lot of cruft
if you do that.

Note that we've got a lot of code that allocates during cleanup. I did an
abort() when somebody tried that. Wasn't pretty :-)

Sometime over the week, I'll see if I can clean up my patch to allow (again)
the allocate-during-cleanup and post that; basically it would just stop
register-during-cleanup.

Hmm. Well, I've just attached my patch. It doesn't do the right thing, but
it could be simplified to scope it down.

> The problem is registering cleanups in a pool in the process of being
> cleaned up.  Opening files, like a lot of other APR operations, registers
> a cleanup with the pool being passed in.  It probably wouldn't even be that
> hard to allow registering cleanups during cleanup; I'll look into that.

Set pool->cleanups to NULL before running them. After you're done running
them, run again if cleanups != NULL. Note the potential for an infinite
loop... :-)

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/

Re: Allocating from a pool in cleanup

Posted by Philip Martin <ph...@codematters.co.uk>.
Greg Hudson <gh...@MIT.EDU> writes:

> On Mon, 2002-11-11 at 06:28, Philip Martin wrote:
> > I don't think that runs the cleanups in the ideal order.  Given two
> > cleanups cleanupA and cleanupB, with cleanupA run before cleanupB,
> > then if cleanupA registers cleanupC I would expect cleanupC to run
> > before cleanupB.  Each cleanup that is registered goes to the head of
> > the queue.
> 
> Nothing in apr_pools.h mentions cleanup order, and I cannot think of any
> legitimate design which relies on cleanup order within a particular
> pool.

1.  The documentation in apr_pools.h is far from complete :-)   Try
    determining pool thread safety from the documentation, or any
    restriction on calling apr_pool_cleanup_register during cleanup.

2.  Sander has already stated that the order is first in, last out
    in response to an earlier claim that the order was unspecified.

3.  I cannot image a system that *doesn't* specify the order being
    useful.  We rely on the ordering, to ensure that the access baton
    cleanup happens before the apr_xlate_t cleanup.

-- 
Philip Martin

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: Allocating from a pool in cleanup

Posted by Greg Hudson <gh...@MIT.EDU>.
On Mon, 2002-11-11 at 06:28, Philip Martin wrote:
> I don't think that runs the cleanups in the ideal order.  Given two
> cleanups cleanupA and cleanupB, with cleanupA run before cleanupB,
> then if cleanupA registers cleanupC I would expect cleanupC to run
> before cleanupB.  Each cleanup that is registered goes to the head of
> the queue.

Nothing in apr_pools.h mentions cleanup order, and I cannot think of any
legitimate design which relies on cleanup order within a particular
pool.

(On the other hand, this is easy to implement:

  while (p->cleanups)
    {
      cleanup = p->cleanups;
      p->cleanups = cleanup->next;
      cleanup->plain_cleanup_fn(cleanup->data);
    }
)


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: Allocating from a pool in cleanup

Posted by Philip Martin <ph...@codematters.co.uk>.
Greg Stein <gs...@lyra.org> writes:

> > The problem is registering cleanups in a pool in the process of being
> > cleaned up.  Opening files, like a lot of other APR operations, registers
> > a cleanup with the pool being passed in.  It probably wouldn't even be that
> > hard to allow registering cleanups during cleanup; I'll look into that.
> 
> Set pool->cleanups to NULL before running them. After you're done running
> them, run again if cleanups != NULL. Note the potential for an infinite
> loop... :-)

I don't think that runs the cleanups in the ideal order.  Given two
cleanups cleanupA and cleanupB, with cleanupA run before cleanupB,
then if cleanupA registers cleanupC I would expect cleanupC to run
before cleanupB.  Each cleanup that is registered goes to the head of
the queue.

What about allowing the creation of subpools during a cleanup handler
as well?  Just clear any subpools created by running a handler before
running the next, possibly newly added, handler :)

-- 
Philip Martin

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org