[plt-scheme] Implementing engines using threads

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Apr 27 17:51:50 EDT 2004

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



Posted on the users mailing list.