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

From: Vincent St-Amour (stamourv at ccs.neu.edu)
Date: Fri May 3 12:05:13 EDT 2013

At Fri, 3 May 2013 11:56:02 -0400,
Eli Barzilay wrote:
> 
> 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))

I think that introduces another race condition.

If the thread is forced before the `pset!', then `force' would return #f
(line 107 of racket/promise.rkt), since the value inside the `promise/thread'
is not a thread.

Vincent


Posted on the dev mailing list.