[racket-dev] engine-kill from racket/engine

From: Asumu Takikawa (asumu at ccs.neu.edu)
Date: Tue Jun 25 01:44:11 EDT 2013

Hi all,

I was trying to write an example for the racket/engine docs and stumbled
on a case that seems to cause a deadlock. I'm curious if this is
intentional or just accidental behavior.

Here's the example:

  #lang racket
  (require racket/engine)
  (define e (engine (lambda (s) (sleep 5))))
  (thread (lambda () (sleep 2) (engine-kill e)))
  (engine-run never-evt e)

This will never terminate. If you comment out the fourth line, it will
terminate. If you change `never-evt` to 4000 (or any other event that
will become ready), it's also fine.

What seems to be going on is that `engine-kill` does actually kill the
thread underlying the engine. However, `engine-run` is `sync`ed on (1)
the given event (2) the engine being "done" or (3) an exception being
raised.  Since `engine-kill` does not trigger any of those, the `sync`
is blocked.

Cheers,
Asumu

Posted on the dev mailing list.