Great!!
(lambda (e)
(if (inactive-thread-exception? e)
(void)
(raise e)))
I was going to suggest
(define (abort-io thread port)
;; force the thread to abort IO on the port
(input-port-timeout-set! port -inf.0)
(thread-interrupt! thread void))
which works by waking up the thread so that it will attempt the IO operation again after setting the timeout of the port so that it will raise a timeout. If the thread was done with the IO when abort-io is called, the thread will not observe a timeout or be terminated forcibly.
Unfortunately, thread-interrupt! has race condition issues. In particular, if the thread has already terminated (normally or not), the thread-interrupt! function will raise an exception. So this is better:
(define (abort-io thread port)
;; force the thread to abort IO on the port
(input-port-timeout-set! port -inf.0)
(with-exception-catcher
(lambda (e)
(if (inactive-thread-exception? e)
(void)
(raise e)))
(lambda ()
(thread-interrupt! thread void))))
While it is logically correct, it is not perfect because thread-interrupt! currently has a bug when a started but not-executed-yet thread is interrupted. But this may not affect your code and I plan to fix the bug soon.
Marc