[gambit-list] Wills from beyond.

Marc Feeley feeley at iro.umontreal.ca
Mon Dec 23 13:06:29 EST 2013


On Dec 23, 2013, at 12:51 PM, Estevo <euccastro at gmail.com> wrote:

> > Yes.  So to be clearer, Gambit’s runtime system keeps a weak reference 
> > to each will created with make-will.  The weak reference is severed when 
> > the will’s action procedure is executed, making the will unreachable.  This
> > allows the will object itself to be reclaimed after the action procedure is
> > executed.
> 
> Clearer indeed!
> 
> Just for the benefit of anyone following this (i.e. this is not a question), I inferred this in the gsi REPL: the weak reference to the will seems to be severed even if the action procedure has made the object reachable again (e.g. by setting a global variable to it).  Now, even if you keep a strong reference to the will, its action procedure *won't* execute when the object becomes weakly reachable again.
> 
> > (define o (cons 'o 'o))                                    
> > (define w (make-will o (lambda (x) (println "saving o") (set! o x))))
> > (set! o #f)
> > (##gc)
> saving o
> > (set! o #f)
> > (##gc)
> > w
> #<will #3>
> 

Will action procedures are “single shot”.  When the GC detects that an object has become weakly reachable, it schedules the will’s action procedure to be executed.  This happens only once.  If you want to detect subsequent transitions from strongly reachable to weakly reachable, just create a new will for this.

Marc




More information about the Gambit-list mailing list