Hi all,
I'm probably doing something wrong here, but for some reason
"custodian-shutdown-all" doesn't always interrupt the execution as the
last test case below shows. It continues execution until finished.
Any ideas how to get this working?
br, jukka
---
#lang racket/load
(require math/number-theory)
(define (when-works-in-given-seconds time-limit thunk)
(define start-time 0)
(define output "initial-state")
(define main-cust (make-custodian))
(define thread:thunk "")
(define (loop delay)
(cond ((not (equal? "initial-state" output))
(begin (custodian-shutdown-all main-cust)
output))
((> (- (current-seconds) start-time) time-limit)
(begin (custodian-shutdown-all main-cust)
"Time-limit exceeded!"))
(else (begin (- (current-seconds) start-time)
(sleep delay)
(loop delay) ))))
(set! start-time (current-seconds))
(thread (lambda () (parameterize ((current-custodian main-cust))
(thread (lambda () (with-handlers ((exn:fail?
(lambda (exn) (set! output "Execution failed!")))) (set! output (eval
thunk))))))))
(loop 0.1))
;test cases
(print (when-works-in-given-seconds 2 '(/ 5 5)))
(newline)(sleep 2)
(print (when-works-in-given-seconds 2 '(/ 5 0)))
(newline)(sleep 2)
(print (when-works-in-given-seconds 2 '(sleep 10)))
(newline)(sleep 2)
(print (when-works-in-given-seconds 2 '(factorial 20000)))
--
You received this message because you are subscribed to the Google Groups "Racket
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.