Re: How to handle endless loops of Interpreter.eval()?

"Marco Bakera" <[email protected]>
Newsgroups gmane.comp.java.sisc.user
Message-ID <[email protected]>
OK, so it's part of scheme implementation to handle this. Perhaps
someone else might be interested in my solution, so I provide it here.

;; need this for threading
(require-extension (srfi 18))

(define (watch thunk max-running-time timeout-val)
  (let ((t (make-thread thunk)))
    ;; starting thread
    (thread-start! t)

    ;; now lets try to join and collect the join result
    (let ((join-result (thread-join! t max-running-time 'timeout)))

      (if (equal? join-result 'timeout)
	  ;; join did not occur in maximum time so lets return given timeout value
	  (begin
	    (thread-terminate! t)
	    timeout-val)
	  ;; join successful so lets return result of computation
	  join-result))))

On 4/17/06, Matthias Radestock <[email protected]> wrote:
> "Marco Bakera" <[email protected]> writes:
>
> > I have some problem handling endless loops produced by
> > Interpreter.eval(). How is it possible to stop some evaluation of the
> > Interpreter after a certain amount of time - e.g. after some time out
> > occured?
>
> Take a look at the code for sarahbot, the irc bot that, amongst other
> things, contains a sandboxed, resource-constrained Scheme evaluator.
>
> You can find the code in the 'contrib' cvs module, under the 'irc'
> directory.
>
> Regarding your specific query, sarahbot has an |eval-within-n-ms|
> procedure, defined in contrib/irc/scheme/sarah/plugins/scheme.scm.
>
>
> Matthias.
>
>


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.