doc and test updates for a sandbox repair

This commit is contained in:
Matthew Flatt 2018-10-11 16:03:03 -06:00
parent ad7797e2cf
commit dbb74b5814
2 changed files with 24 additions and 9 deletions

View File

@ -715,7 +715,7 @@ The memory limit that is specified by this parameter applies to each
individual evaluation, but not to the whole sandbox --- that limit is individual evaluation, but not to the whole sandbox --- that limit is
specified via @racket[sandbox-memory-limit]. When the global limit is specified via @racket[sandbox-memory-limit]. When the global limit is
exceeded, the sandbox is terminated, but when the per-evaluation limit exceeded, the sandbox is terminated, but when the per-evaluation limit
is exceeded the @exnraise[exn:fail:resource]. For example, say that is exceeded, an exception recognizable by @racket[exn:fail:resource?] is raised. For example, say that
you evaluate an expression like you evaluate an expression like
@racketblock[ @racketblock[
(for ([i (in-range 1000)]) (for ([i (in-range 1000)])
@ -1040,7 +1040,7 @@ checked at the time that a sandbox evaluator is created.}
Executes the given @racket[thunk] with memory and time restrictions: Executes the given @racket[thunk] with memory and time restrictions:
if execution consumes more than @racket[mb] megabytes or more than if execution consumes more than @racket[mb] megabytes or more than
@racket[secs] @tech{shallow time} seconds, then the computation is @racket[secs] @tech{shallow time} seconds, then the computation is
aborted and the @exnraise[exn:fail:resource]. Otherwise the result of aborted and an exception recognizable by @racket[exn:fail:resource?] is raised. Otherwise, the result of
the thunk is returned as usual (a value, multiple values, or an the thunk is returned as usual (a value, multiple values, or an
exception). Each of the two limits can be @racket[#f] to indicate the exception). Each of the two limits can be @racket[#f] to indicate the
absence of a limit. See also @racket[custodian-limit-memory] for absence of a limit. See also @racket[custodian-limit-memory] for
@ -1059,8 +1059,15 @@ A macro version of @racket[call-with-limits].}
@defproc[(call-with-deep-time-limit [secs exact-nonnegative-integer?] @defproc[(call-with-deep-time-limit [secs exact-nonnegative-integer?]
[thunk (-> any)]) [thunk (-> any)])
any]{ any]{
Executes the given @racket[thunk] with @tech{deep time} restrictions. Executes the given @racket[thunk] with @tech{deep time} restrictions,
} and returns the values produced by @racket[thunk].
The given @racket[thunk] is run in a new thread. If it errors or if
the thread terminates returning a value, then @racket[(values)] is
returned.
@history[#:changed "1.1" @elem{Changed to return @racket[thunk]'s result
if it completes normally.}]}
@defform[(with-deep-time-limit secs-expr body ...)]{ @defform[(with-deep-time-limit secs-expr body ...)]{

View File

@ -9,11 +9,19 @@
(require rackunit) (require rackunit)
(define n 1) (define n 1)
(check-not-exn (check-equal?
(λ () (with-deep-time-limit
(with-deep-time-limit n
n (begin (sleep (sub1 n)) 'done))
(sleep (sub1 n))))) 'done)
(check-equal?
(call-with-values
(lambda ()
(with-deep-time-limit
n
(kill-thread (current-thread))))
list)
null)
(check-exn (check-exn
exn:fail:resource:time? exn:fail:resource:time?
(λ () (λ ()