Opened 13 years ago

Closed 13 years ago

Last modified 12 years ago

#447 closed defect (fixed)

Inconsistency when calling set-finalizer! multiple times on the same object

Reported by: Moritz Heidkamp Owned by:
Priority: major Milestone: 4.9.0
Component: unknown Version: 4.6.x
Keywords: Cc:
Estimated difficulty:

Description

The following program prints "b" when interpreted and "ba" when compiled:

(define x (list 1))
(set-finalizer! x (lambda (x) (display 'a)))
(set-finalizer! x (lambda (x) (display 'b)))
(set! x #f)

I am not sure whether replacing the existing finalizer or appending another finalizer makes more sense. However, it would probably be better if both cases behaved the same.

Change History (5)

comment:1 Changed 13 years ago by Jim Ursetto

Weird. I increased your finalizers to 3 and added a (gc #t) to the end as well. Both cases look like they are behaving strangely.

Compiled:

;; (gc #t)
[debug] running 1 finalizers (2 live, 3 allocated) ...
c[debug] running 1 finalizers (1 live, 3 allocated) ...
b[debug] running 1 finalizers (0 live, 3 allocated) ...
;; program end
[debug] forcing finalizers...
a[debug] application terminated normally

Interpreted (csi -script):

;; (gc #t)
[debug] running 1 finalizers (2 live, 3 allocated) ...
;; program end
[debug] forcing finalizers...
c[debug] application terminated normally

comment:2 Changed 13 years ago by felix winkelmann

Resolution: fixed
Status: newclosed

This should be fixed now (experimental). The code that walked the finalizer list checks for a finalized object being not forwarded into the new heap area on GC. Previously it marked the object, hiding the "non-forwarded" status for later finalizers for the same object in the finalizer list, which would then never be run. The list is now walked twice, once for checking, and once for marking. GC frequency and the location of objects in memory influence strongly how and when finalizers are checked and executed.

I have tried to improve the documentation.

comment:3 Changed 13 years ago by Moritz Heidkamp

Works like a charm, thanks a lot :-) The docs are clear to me now!

comment:4 Changed 13 years ago by felix winkelmann

Milestone: 4.7.04.8.0

Milestone 4.7.0 deleted

comment:5 Changed 12 years ago by felix winkelmann

Milestone: 4.8.04.9.0

Milestone 4.8.0 deleted

Note: See TracTickets for help on using tickets.