Great!!
Can't wait to try it out!
(lambda (e)
(if (inactive-thread-exception? e) (void) (raise e)))
This condition that can make it raise an exception, could that ever be of any practical value beyond typechecking of the thread?
Would probably be interested in making the exception-catcher return #!void always unless if there could come some valuable debug info out of there.
Thanks, Mikael
2013/3/18 Marc Feeley feeley@iro.umontreal.ca ..
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