Index: /branches/win64/lisp-kernel/thread_manager.c
===================================================================
--- /branches/win64/lisp-kernel/thread_manager.c	(revision 9652)
+++ /branches/win64/lisp-kernel/thread_manager.c	(revision 9653)
@@ -59,4 +59,9 @@
 extern void interrupt_handler(int, siginfo_t *, ExceptionInformation *);
 
+BOOL (*pCancelIoEx)(HANDLE, OVERLAPPED*) = NULL;
+
+
+extern void *windows_find_symbol(void*, char*);
+
 int
 raise_thread_interrupt(TCR *target)
@@ -69,4 +74,5 @@
   area *cs = target->cs_area, *ts = target->cs_area;
   DWORD rc;
+  BOOL io_pending;
 
   pcontext = (CONTEXT *)((((natural)&_contextbuf)+15)&~15);
@@ -82,4 +88,5 @@
     wperror("GetThreadContext");
   }
+
   where = (pc)(xpPC(pcontext));
   
@@ -97,6 +104,15 @@
     /* If the thread's in a blocking syscall, it'd be nice to
        get it out of that state here. */
+    GetThreadIOPendingFlag(hthread,&io_pending);
     target->interrupt_pending = (1LL << (nbits_in_word - 1LL));
     ResumeThread(hthread);
+    if (io_pending) {
+      pending_io * pending = (pending_io *) (target->foreign_exception_status);
+      if (pCancelIoEx) {
+        pCancelIoEx(pending->h, pending->o);
+      } else {
+        CancelIo(pending->h);
+      }
+    }
     return 0;
   } else {
@@ -104,5 +120,5 @@
        so that it calls out and then returns to the context,
        handling any necessary pc-lusering. */
-    LispObj foreign_rsp = (((LispObj)(target->foreign_sp))-128)&~15;
+    LispObj foreign_rsp = (((LispObj)(target->foreign_sp))-0x200)&~15;
     CONTEXT *icontext = ((CONTEXT *) foreign_rsp) -1;
     icontext = (CONTEXT *)(((LispObj)icontext)&~15);
@@ -1154,4 +1170,5 @@
 #ifdef WINDOWS
   lisp_global(TCR_KEY) = TlsAlloc();
+  pCancelIoEx = windows_find_symbol(NULL, "CancelIoEx");
 #else
   pthread_key_create((pthread_key_t *)&(lisp_global(TCR_KEY)), shutdown_thread_tcr);
