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

Re: [Scheme-reports] valid implementation of call-with-input-file?



On Mon, Aug 20, 2012 at 4:55 PM, Andy Wingo <wingo@x> wrote:
> On Mon 20 Aug 2012 05:22, Alex Shinn <alexshinn@x> writes:
>
>> It's expected that implementations close files on
>> gc, and a good implementation should gc when out
>> of file descriptors as well.  An alternate approach
>> to more timely releasing of resources would be
>> to add stronger guarantees about when gc occurs -
>> again, an area of open research not yet ready for
>> WG1.
>
> Leaving file closing to GC is the wrong thing to design for.  It's an OK
> fallback but it's not a good base case.

Indeed, which is why I only suggested it as a
potential starting point, and an open area of
research.

> Part of the reason is that files are closed during finalization, which
> does not have to run when GC runs.  The Java world, for example, has
> standardized on running finalizers in a separate thread.  Guile does
> this as well, when possible.  So running GC might not have the effect of
> closing files.

You don't necessarily need to limit yourself to
finalizers in the traditional sense.

An interesting idea posed by Taylor Campbell
was to attach a finalizer to the final continuation
of the body.  If it is no longer reachable, the
continuation can no longer be re-entered, and
it's safe to reclaim the resources.  The trick is
being able to detect this as soon as possible.

> There are a number of Scheme systems out there that support what Peter
> and I want to do.  Guile's `with-throw-handler' is one example.  I'm
> sure Chicken has something as well.

Sure, this is simple and as I said I had already
proposed it myself, but it doesn't solve the
general case.  We need a little more experience
with this, contrasting different approaches by
existing implementations.  Any help you want
to provide for specifying this in WG2 would be
very much appreciated!

-- 
Alex

_______________________________________________
Scheme-reports mailing list
Scheme-reports@x
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports