-are no more references to OBJECT. In a multithreaded environment
-the finalizer may run in any thread."
- (sb!thread:with-mutex (*finalizer-store-lock*)
- (push (cons (make-weak-pointer object) function)
- *finalizer-store*))
+are no more references to OBJECT, including references in
+FUNCTION itself.
+
+In a multithreaded environment FUNCTION may be called in any
+thread. In both single and multithreaded environments FUNCTION
+may be called in any dynamic scope: consequences are unspecified
+if FUNCTION is not fully re-entrant.
+
+Errors from FUNCTION are handled and cause a WARNING to be
+signalled in whichever thread the FUNCTION was called in.
+
+Examples:
+
+ ;;; good (assumes RELEASE-HANDLE is re-entrant)
+ (let* ((handle (get-handle))
+ (object (make-object handle)))
+ (finalize object (lambda () (release-handle handle)))
+ object)
+
+ ;;; bad, finalizer refers to object being finalized, causing
+ ;;; it to be retained indefinitely
+ (let* ((handle (get-handle))
+ (object (make-object handle)))
+ (finalize object (lambda () (release-handle (object-handle object)))))
+
+ ;;; bad, not re-entrant
+ (defvar *rec* nil)
+
+ (defun oops ()
+ (when *rec*
+ (error \"recursive OOPS\"))
+ (let ((*rec* t))
+ (gc))) ; or just cons enough to cause one
+
+ (progn
+ (finalize \"oops\" #'oops)
+ (oops)) ; causes GC and re-entry to #'oops due to the finalizer
+ ; -> ERROR, caught, WARNING signalled"
+ (with-finalizer-store-lock
+ (push (cons (make-weak-pointer object) function)
+ *finalizer-store*))