Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!mips!cs.uoregon.edu!ogicse!pdxgate!parsely!percy!data!kend From: kend@data.UUCP (Ken Dickey) Newsgroups: comp.lang.scheme Subject: Re: Ports & GC Message-ID: <480@data.UUCP> Date: 26 Apr 91 15:40:30 GMT References: <6260006@otter.hpl.hp.com> Organization: Microcosm, Beaverton, OR Lines: 40 sfk@otter.hpl.hp.com (Steve Knight) writes: >I've been reading the most recent draft standard I've got (Nov89) and can't >determine the answer to the following question. When a port is garbage >collected, is it automatically closed on your behalf? ... This is unspecified in the standard. >If this isn't a question answered by the draft standard then I'd appreciate >knowing the general implementation strategies. Here are a couple: Maintain a table of open ports. At collection time, scan the table and close any ports which have been collected. Implement finalization objects. I did this in a local copy of the Gambit runtime (v1.5) by implementing weak-pairs (the car goes to nil when collected). The finalization procedure registers each object to be finalized with a thunk which does the cleanup. The object is in the car of a weak pair, the thunk in the cdr. After a collection, the weak-pairs are scanned and any who's car is nil is thrown away after the finalization thunk is invoked. {The rules are that such a thunk does not cons and does not invoke random continuations.} ========== A finalization service is also helpful for freeing storage for dumb allocators like C's malloc. Weaks/populations, etc. are helpful in a variety of ways. Weak-pairs are easy to implement in a stop-and-copy collector, by the way. There is a very clear description of this in Jim Millers thesis: "MultiScheme", MIT/LCS/TR-402, September 1987. I can send you code if that is interesting. -Ken Dickey kend@data.uucp