From 2d695be78cb4b639d56b386e89c56aae0f3f3d99 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Mon, 16 Dec 2019 08:58:08 -0700 Subject: [PATCH] racket/promise: repairs for custodian change Closes #2973 Note that the test is in the "lazy" package, commit 2cc3a24343. --- racket/collects/racket/promise.rkt | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/racket/collects/racket/promise.rkt b/racket/collects/racket/promise.rkt index 922d38467d..b1a15d77e3 100644 --- a/racket/collects/racket/promise.rkt +++ b/racket/collects/racket/promise.rkt @@ -117,11 +117,15 @@ (thread-group? group)) (raise-argument-error 'delay/thread "(or/c thread-group? #f)" group)) (define initialized-sema (make-semaphore)) + (define orig-c (current-custodian)) (define (run) (semaphore-wait initialized-sema) ; wait until p is properly defined (call-with-exception-handler - (λ(e) (pset! p (make-reraise e)) (kill-thread (current-thread))) - (λ() (pset! p (call-with-values thunk list))))) + (λ (e) + (pset! p (make-reraise e)) + (parameterize ([current-custodian orig-c]) + (kill-thread (current-thread)))) + (λ () (pset! p (call-with-values thunk list))))) (define p (make-promise/thread (make-running-thread @@ -164,10 +168,14 @@ (define use (cond [(use* . <= . 0) 0] [(use* . >= . 1) 1] [else use*])) (define work-time (* tick use)) (define rest-time (- tick work-time)) + (define orig-c (current-custodian)) (define (work) (call-with-exception-handler - (λ(e) (pset! p (make-reraise e)) (kill-thread (current-thread))) - (λ() (pset! p (call-with-values thunk list))))) + (λ (e) + (pset! p (make-reraise e)) + (parameterize ([current-custodian orig-c]) + (kill-thread (current-thread)))) + (λ () (pset! p (call-with-values thunk list))))) (define (run) ;; this thread is dedicated to controlling the worker thread, so it's ;; possible to dedicate messages to signaling a `force'.