diff --git a/pkgs/racket-test/tests/racket/custodian-finalize-help.rkt b/pkgs/racket-test/tests/racket/custodian-finalize-help.rkt new file mode 100644 index 0000000000..dc9ad9010b --- /dev/null +++ b/pkgs/racket-test/tests/racket/custodian-finalize-help.rkt @@ -0,0 +1,25 @@ +#lang racket/base +(require ffi/unsafe/custodian) + +;; This module is run by "custodian-finalize.rkt" + +(define (log-info x) + (log-message (current-logger) 'info 'finalize x)) + +(define (finalize x) + (log-info "finalizing")) + +(define the-box + (let ([v (string-copy "a value")]) + (register-finalizer-and-custodian-shutdown v finalize #:at-exit? #t) + (log-info "created") + (box v))) + +(module* check-gc #f + (set-box! the-box #f) + (collect-garbage 'major) + (sync (system-idle-evt)) + (log-info "exiting")) + +(module* check-exit #f + (log-info "exiting")) diff --git a/pkgs/racket-test/tests/racket/custodian-finalize.rkt b/pkgs/racket-test/tests/racket/custodian-finalize.rkt new file mode 100644 index 0000000000..b9eab7c8ec --- /dev/null +++ b/pkgs/racket-test/tests/racket/custodian-finalize.rkt @@ -0,0 +1,30 @@ +#lang racket/base +(require compiler/find-exe + racket/system) + +(define racket (find-exe)) + +(define result 0) + +(define (run/get-stderr . args) + (define o (open-output-bytes)) + (parameterize ([current-error-port o]) + (apply system* racket args)) + (get-output-bytes o)) + +(define (check expect got) + (unless (equal? expect got) + (eprintf "Expected ~s,\n got ~s\n" expect got) + (set! result 1))) + +(check #"finalize: created\nfinalize: exiting\nfinalize: finalizing\n" + (run/get-stderr "-W" "info@finalize" + "-e" + "(dynamic-require '(submod \"custodian-finalize-help.rkt\" check-exit) #f)")) + +(check #"finalize: created\nfinalize: finalizing\nfinalize: exiting\n" + (run/get-stderr "-W" "info@finalize" + "-e" + "(dynamic-require '(submod \"custodian-finalize-help.rkt\" check-gc) #f)")) + +(exit result) diff --git a/racket/src/cs/schemified/thread.scm b/racket/src/cs/schemified/thread.scm index 0184d21319..b69d6e7c37 100644 --- a/racket/src/cs/schemified/thread.scm +++ b/racket/src/cs/schemified/thread.scm @@ -5679,7 +5679,7 @@ #f (let ((we_0 (if (not weak?7_0) - (|#%app| host:make-will-executor void) + (|#%app| host:make-late-will-executor void) #f))) (begin (let ((app_0 (custodian-children cust12_0))) diff --git a/racket/src/thread/custodian.rkt b/racket/src/thread/custodian.rkt index 5dc1c4452c..012a17e3e8 100644 --- a/racket/src/thread/custodian.rkt +++ b/racket/src/thread/custodian.rkt @@ -122,7 +122,7 @@ [(custodian-shut-down? cust) #f] [else (define we (and (not weak?) - (host:make-will-executor void))) + (host:make-late-will-executor void))) (hash-set! (custodian-children cust) obj (cond