+ while ((numFound = select(maxfd+1, &rfd, &wfd, NULL, &tv)) < 0) {
+ if (errno != EINTR) {
+ /* Handle bad file descriptors by unblocking all the
+ waiting threads. Why? Because a thread might have been
+ a bit naughty and closed a file descriptor while another
+ was blocked waiting. This is less-than-good programming
+ practice, but having the RTS as a result fall over isn't
+ acceptable, so we simply unblock all the waiting threads
+ should we see a bad file descriptor & give the threads
+ a chance to clean up their act.
+
+ 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 ) {
+ unblock_all = rtsTrue;
+ break;
+ } else {
+ fprintf(stderr,"%d\n", errno);
+ fflush(stderr);
+ perror("select");
+ barf("select failed");
+ }
+ }
+#else /* on mingwin */
+#ifdef RTS_SUPPORTS_THREADS
+ isWorkerBlockedInAwaitEvent = rtsTrue;
+#endif
+ RELEASE_LOCK(&sched_mutex);
+ while (1) {
+ Sleep(0); /* don't busy wait */
+#endif /* mingw32_TARGET_OS */
+ ACQUIRE_LOCK(&sched_mutex);
+#ifdef RTS_SUPPORTS_THREADS
+ isWorkerBlockedInAwaitEvent = rtsFalse;