[project @ 2002-11-20 15:40:32 by simonpj]
[ghc-hetmet.git] / ghc / rts / Select.c
index 922b151..dc19cbf 100644 (file)
@@ -1,7 +1,7 @@
 /* -----------------------------------------------------------------------------
- * $Id: Select.c,v 1.20 2002/07/09 20:44:24 sof Exp $
+ * $Id: Select.c,v 1.22 2002/07/24 03:38:58 sof Exp $
  *
- * (c) The GHC Team 1995-1999
+ * (c) The GHC Team 1995-2002
  *
  * Support for concurrent non-blocking I/O and thread waiting.
  *
@@ -29,6 +29,9 @@
 #  include <windows.h>
 # endif
 
+#include <errno.h>
+#include <string.h>
+
 /* last timestamp */
 nat timestamp = 0;
 
@@ -87,7 +90,6 @@ awaitEvent(rtsBool wait)
 #endif
     rtsBool select_succeeded = rtsTrue;
     rtsBool unblock_all = rtsFalse;
-    static rtsBool prev_unblocked_all = rtsFalse;
     struct timeval tv;
     lnat min, ticks;
 
@@ -185,12 +187,16 @@ awaitEvent(rtsBool wait)
               should we see a bad file descriptor & give the threads
               a chance to clean up their act. 
               
-              To avoid getting stuck in a loop, repeated EBADF failures
-              are 'handled' through barfing.
+              Note: assume here that threads becoming unblocked
+              will try to read/write the file descriptor before trying
+              to issue a threadWaitRead/threadWaitWrite again (==> an
+              IOError will result for the thread that's got the bad
+              file descriptor.) Hence, there's no danger of a bad
+              file descriptor being repeatedly select()'ed on, so
+              the RTS won't loop.
            */
-           if ( errno == EBADF && !prev_unblocked_all) {
+           if ( errno == EBADF ) {
              unblock_all = rtsTrue;
-             prev_unblocked_all = rtsTrue;
              break;
            } else {
              fprintf(stderr,"%d\n", errno);
@@ -205,8 +211,6 @@ awaitEvent(rtsBool wait)
 #endif /* mingw32_TARGET_OS */
          ACQUIRE_LOCK(&sched_mutex);
 
-         prev_unblocked_all = rtsFalse;
-
 #ifndef mingw32_TARGET_OS
          /* We got a signal; could be one of ours.  If so, we need
           * to start up the signal handler straight away, otherwise