Index: /trunk/ccl/lisp-kernel/thread_manager.c
===================================================================
--- /trunk/ccl/lisp-kernel/thread_manager.c	(revision 664)
+++ /trunk/ccl/lisp-kernel/thread_manager.c	(revision 665)
@@ -148,5 +148,4 @@
 }
 
-  
 int
 wait_on_semaphore(SEMAPHORE s, int seconds, int nanos)
@@ -167,7 +166,36 @@
 #ifdef DARWIN
   mach_timespec_t q = {seconds, nanos};
-  return SEM_TIMEDWAIT(s, q);
-#endif
-}
+  do {
+    clock_t start = clock();
+
+    int status = SEM_TIMEDWAIT(s, q);
+    clock_t finish = clock();
+
+    if (status == KERN_ABORTED) {
+      clock_t elapsed = (finish - start);
+
+      int elapsed_seconds = elapsed/CLOCKS_PER_SEC;
+      int elapsed_nanos = (elapsed - (elapsed_seconds * CLOCKS_PER_SEC)) * 1000000000/CLOCKS_PER_SEC;
+
+      seconds = seconds - elapsed_seconds - (elapsed_nanos/1000000000);
+      if (nanos  > 0) {
+	nanos = 1000000000 - elapsed_nanos;
+      }
+
+      if ((seconds <= 0) && (nanos <= 0)) {
+	return 0;
+      }
+
+      q.tv_sec = seconds;
+      q.tv_nsec = nanos;
+    } else {
+      return status;
+    }
+  } while (1==1);
+  // Possible limit on number of retries? 
+
+#endif
+}
+
 
 void
@@ -749,4 +777,5 @@
       current->vs_area->active -= 4;
     }
+    current->shutdown_count = 1;
     ((void (*)())ptr_from_lispobj(callback_ptr))(0);
 
