[plt-scheme] Implementing engines using threads
At Tue, 27 Apr 2004 23:39:14 +0200, Jens Axel Søgaard wrote:
> but it goes with out saying that a continuation captured in one thread
> can not be reified in another.
... unless you use version 299.2 or later (which has other problems,
for now).
> Is there an elegant way to communicate the return value of success to
> the caller of the engine?
I think you'll have to use `set!':
(define (make-engine a-thunk)
(lambda (ticks success failure)
(let ([result #f])
(let ([work-thread (thread (lambda () (set! result (a-thunk))))])
...
(if (not (object-wait-multiple ticks work-thread))
(begin
(thread-suspend work-thread)
(failure new-engine))
(success result))
...))))
Matthew