[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Continuation safety

For an example you might want to at plt/collects/web-server/web-server.ss
in the function server-loop.

Custodians allow you to clean up---in one action in one place---a whole bunch
of ports, threads, etc that were opened in code that may be loaded dynamically,
or code that is scattered about.  An exception handler will ensure that the
shutdown happens even in the presence of exceptions.  Dynamic-wind will
ensure that the shutdown occurs in the presence of continuations.  Notice
that with custodians you don't need a reference to the open ports, which may
be available only in some lexical scope that the thread escaped out of.


On Fri, Feb 08, 2002 at 12:49:24PM -0500, Chris Uzdavinis wrote:
> I'm interested in writing Scheme code, but when it creates threads,
> opens files, and so on, what are the normal steps toward guaranteeing
> that they're freed?  I'm afraid that my code is in general lacking
> such robustness.
> I hear mention of custodians but don't really understand how to use
> them.  The PLT Scheme Language Manual dedicates less than 1/3 of a
> page to custodians, and I'm wondering where I could find introductary
> documentation for this concept, especially some kind of example of how
> and when to put them use, how to rely on them to solve a job, etc.  If
> I have to call (custodian-shutdown-all ...) in order to invoke a
> custodian, what prevents a continuation from bypassing that call too?
> Is a custodian the right way to make code continuation-safe?  What
> other techniques are used?
> Thanks very much in advance.
> -- 
> Chris