diff --git a/rts/posix/Select.c b/rts/posix/Select.c index a3f2ae301fcf61355200ce8e3cf8d9b72c55245d..0b3f750a979c246d2e936bc0893cbc939b4d68ad 100644 --- a/rts/posix/Select.c +++ b/rts/posix/Select.c @@ -217,10 +217,19 @@ awaitEvent(rtsBool wait) ptv = NULL; } - /* Check for any interesting events */ - - while ((numFound = select(maxfd+1, &rfd, &wfd, NULL, ptv)) < 0) { - if (errno != EINTR) { + while (1) { // repeat the select on EINTR + + // Disable the timer signal while blocked in + // select(), to conserve power. (#1623, #5991) + if (wait) stopTimer(); + + numFound = select(maxfd+1, &rfd, &wfd, NULL, ptv); + + if (wait) startTimer(); + + if (numFound >= 0) break; + + 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