[racket-dev] TR tests sometimes fail with a promise error

From: Eli Barzilay (eli at barzilay.org)
Date: Fri May 3 11:56:02 EDT 2013

A few minutes ago, Vincent St-Amour wrote:
> Sam, Asumu and I found and fixed the bug. Here's the problem in a
> nutshell.
> 
> This is the implementation of `delay/thread' from racket/promise.
> 
>     (define (delay/thread thunk)
>       (let ()
>         (define (run)
>           (call-with-exception-handler
>            (lambda (e) (pset! p (make-reraise e)) (kill-thread (current-thread)))
>            (lambda () (pset! p (call-with-values thunk list)))))
>         (define p
>           (make-promise/thread
>            (make-running-thread
>             (object-name thunk)
>             (thread run))))
>         p))
> [...]
> Our solution is to have `run' block on a channel until `p' is fully
> initialized. I'll push the fix.

I haven't looked at the code recently, but I think that something
along these lines can work instead of some explicit syncing:

    (define (delay/thread thunk)
      (let ()
        (define p (make-promise/thread #f))
        (pset! p (make-running-thread (thread (λ() ...same...))))
        p))


-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!


Posted on the dev mailing list.