This page is part of the web mail archives of SRFI 68 from before July 7th, 2015. The new archives for SRFI 68 contain all messages, not just those from before July 7th, 2015.
From: Michael Sperber <sperber@xxxxxxxxxxxxxxxxxxxxxxxxxxx> Subject: Re: closing reader / writer Date: Wed, 08 Jun 2005 09:24:58 +0200 > Shiro Kawai <shiro@xxxxxxxx> writes: > > > What I can do in the 'close' procedure is affected so much by > > whether 'close' procedure may be called from finalizers or not. > > Because of the asynchronous nature of the finalizers, > > when the finalizer is involved, I need to write 'close' procedure > > with care as if I'm writing preemptive multithreaded program, > > even if the program itself is single threaded. > > I don't understand how the asynchronous nature of finalizers comes in: > By nature, in this scenario, the finalizer can only be called *after* > the Scheme program is finished with a reader or writer, so no > interleaving with explicit calls from the user program is possible. Suppose I'm managing a pool of resources for a special kind of reader (or writer). Every time such a reader is requested, my constructor allocates the resource from the pool, calls make-simple-reader, and return the created reader. Every time the reader is closed, my 'close' procedure returns the resource to the pool. If the 'close' procedure can be called from finalizers, it is possible that the 'close' procedure is called while the constructor is running to create another reader. So a race condition on the access to the resouce pool can happen. --shiro