Great!!<div><br>Can't wait to try it out!</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


   (lambda (e)<br>     (if (inactive-thread-exception? e)<br>         (void)<br>         <span style="background-color:rgb(255,255,204)">(raise e)</span>))</blockquote><div><br></div><div>This condition that can make it raise an exception, could that ever be of any practical value beyond typechecking of the thread?</div>


<div><br></div><div>Would probably be interested in making the exception-catcher return #!void always unless if there could come some valuable debug info out of there.</div><div><br></div><div>Thanks,</div><div>Mikael<br>


<br><div class="gmail_quote">2013/3/18 Marc Feeley <span dir="ltr"><<a href="mailto:feeley@iro.umontreal.ca" target="_blank">feeley@iro.umontreal.ca</a>></span><br><div>.. </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<div><div>
<br>
</div></div>I was going to suggest<br>
<br>
(define (abort-io thread port)<br>
  ;; force the thread to abort IO on the port<br>
  (input-port-timeout-set! port -inf.0)<br>
  (thread-interrupt! thread void))<br>
<br>
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.<br>



<br>
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:<br>
<br>
(define (abort-io thread port)<br>
<br>
  ;; force the thread to abort IO on the port<br>
<br>
  (input-port-timeout-set! port -inf.0)<br>
<br>
  (with-exception-catcher<br>
   (lambda (e)<br>
     (if (inactive-thread-exception? e)<br>
         (void)<br>
         (raise e)))<br>
   (lambda ()<br>
     (thread-interrupt! thread void))))<br>
<br>
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.<br>



<span><font color="#888888"><br>
Marc<br>
<br>
</font></span></blockquote></div><br></div>