[plt-scheme] threads, breaks, and races

From: Dimitris Vyzovitis (vyzo at media.mit.edu)
Date: Sat Jun 30 02:54:51 EDT 2007

I would expect this code to die silently:
(let ((thr (thread (lambda ()
                     (with-handlers ((void void))
                       (sync never-evt))))))
  (break-thread thr))

Instead, I get this:
(let ((thr (thread (lambda ()
                     (with-handlers ((void void))
                       (sync never-evt))))))
  (break-thread thr))
> user break

In fact, it seems that the break is not delivered to the
target thread at all. Instead, it is captured by the main thread (but
the continuation in the main thread is not broken!):
> (let ((thr (thread (lambda ()
                     (with-handlers ((void void))
                       (sync never-evt))))))
  (break-thread thr)
  (thread-dead? thr))
#f
> user break

Now, if I add a sleep before breaking the thread, the break is delivered
normally:

> (let ((thr (thread (lambda ()
                     (with-handlers ((void void))
                       (sync never-evt) 'boo)))))
  (sleep 1)
  (break-thread thr)
  (sleep 1)
  (thread-dead? thr))
#t
>

-- vyzo



Posted on the users mailing list.