[plt-scheme] Implementing engines using threads

From: Robby Findler (robby at cs.uchicago.edu)
Date: Tue Apr 27 17:56:13 EDT 2004

At Tue, 27 Apr 2004 15:51:50 -0600, Matthew Flatt wrote:
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> 
> 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))
>          ...))))

Can you not use a channel from the work-thread? (Or is that 299 only, I
forget...)

Robby


Posted on the users mailing list.