[gambit-list] Wills from beyond.

Marc Feeley feeley at iro.umontreal.ca
Sun Dec 22 19:08:58 EST 2013

On Dec 21, 2013, at 9:33 PM, Estevo <euccastro at gmail.com> wrote:

> In gsi, a will that has become unreachable will still execute when its testator is about to become unreachable.
> What's more, if the will's action is a closure upon some other object, and if we make that other object unreachable too (such that a different will with that other object as a testator executes), when the action executes it will still be able to access that other object.  This is probably clearer in code:
> > (define o1 (cons 'o 1)) 
> > (define o2 (cons 'o 2))
> > (define w1 (make-will o1 (let ((o2_ o2)) (lambda (x) (println "w1 says bye to " x " but it can still reach " o2_)))))
> > (define w2 (make-will o2 (lambda (x) (println "w2 says bye to o2"))))
> > (define w3 (make-will w1 (lambda (x) (println "w3 says bye to w1"))))
> > (set! w1 #f)                                                                                                         
> > (gc)
> w3 says bye to w1
> > (set! o2 #f)
> > (gc)
> w2 says bye to o2
> > (set! o1 #f)
> > (gc)
> w1 says bye to o1 but it can still reach o2
> > 
> Is this expected semantics, or just accidental behavior that shouldn't be relied upon?

It is expected, in the sense that it is consistent with the rule that a will becomes executable if its testator is not strongly reachable.  Here, after (set! o2 #f), o2 is not strongly reachable.  The will w1 isn’t strongly reachable, so w1’s action closure isn’t strongly reachable, so even if its free variable o2_ contains a pointer to o2, there isn’t a strong chain from a root which reaches o2.

> If o2 was a foreign object with a finalizer, would it have been released by the time w1 executed, or would w1's closure reference have kept it alive?

The GC only calls the finalizer (release function?) when it reclaims the space of the object.  So as long as you can get your hands on o2 (when w1’s action procedure is executed), the finalizer will not have been called.


More information about the Gambit-list mailing list