From 3fcc58c05e6efce405c113b43122956cbe7fa4a9 Mon Sep 17 00:00:00 2001 From: Eli Barzilay Date: Fri, 12 Dec 2008 13:43:05 +0000 Subject: [PATCH] minor improvements svn: r12789 --- collects/scheme/sandbox.ss | 10 +++++++--- collects/tests/mzscheme/sandbox.ss | 14 +++++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/collects/scheme/sandbox.ss b/collects/scheme/sandbox.ss index 0344771556..af0312be5a 100644 --- a/collects/scheme/sandbox.ss +++ b/collects/scheme/sandbox.ss @@ -223,7 +223,7 @@ ;; similar to `call-in-nested-thread', but propagates killing the thread, ;; shutting down the custodian or setting parameters and thread cells; -;; optionally with thunks to call for kill/shutdown. +;; optionally with thunks to call for kill/shutdown instead. (define (call-in-nested-thread* thunk [kill (lambda () (kill-thread (current-thread)))] @@ -270,8 +270,12 @@ (thread (lambda () (sleep sec) (set! r 'time) (kill-thread t))))) (set! r (with-handlers ([void (lambda (e) (list raise e))]) (call-with-values thunk (lambda vs (list* values vs)))))) - (lambda () (unless r (set! r 'kill))) - (lambda () (unless r (set! r 'shut))))) + (lambda () + (unless r (set! r 'kill)) + (kill-thread (current-thread))) + (lambda () + (unless r (set! r 'shut)) + (custodian-shutdown-all (current-custodian))))) (unless (custodian-box-value cust-box) (if (memq r '(kill shut)) ; should always be 'shut (set! r 'memory) diff --git a/collects/tests/mzscheme/sandbox.ss b/collects/tests/mzscheme/sandbox.ss index 10c1068f70..1f78204f8c 100644 --- a/collects/tests/mzscheme/sandbox.ss +++ b/collects/tests/mzscheme/sandbox.ss @@ -7,8 +7,14 @@ ;; test call-in-nested-thread* (let () + (define (kill) (kill-thread (current-thread))) + (define (shut) (custodian-shutdown-all (current-custodian))) (define-syntax-rule (nested body ...) (call-in-nested-thread* (lambda () body ...))) + (define-syntax-rule (nested* body ...) + (call-in-nested-thread* (lambda () body ...) + (lambda () 'kill) + (lambda () 'shut))) (test 1 values (nested 1)) ;; propagates parameters (let ([p (make-parameter #f)]) @@ -19,13 +25,15 @@ ;; propagates kill-thread (test (void) thread-wait (thread (lambda () - (nested (kill-thread (current-thread))) + (nested (kill)) ;; never reach here (semaphore-wait (make-semaphore 0))))) ;; propagates custodian-shutdown-all (test (void) values - (parameterize ([current-custodian (make-custodian)]) - (nested (custodian-shutdown-all (current-custodian)))))) + (parameterize ([current-custodian (make-custodian)]) (nested (shut)))) + ;; test handlers parameters + (test 'kill (lambda () (nested* (kill)))) + (test 'shut (lambda () (nested* (shut))))) (let ([ev void]) (define (run thunk)