- Make fdReady a ccall interruptible
- Move EINTR loop from C into Haskell so that Haskell code can run between interruptions
- Fix ccall interruptible not being interruptible when calling fdReady() on Windows, by using an Event HANDLE to signal interruption
- Call interruptible between fdReady() calls so that exceptions have a chance to be delivered.
- Call yield on the non-threaded RTS between fdReady() calls so that functions like timeout get a chance to produce their exceptions.
- Make the context switch timer call interruptOSThread() to interrupt blocking IO in the non-threaded RTS on platforms where the timer signal doesn't do that automatically.
This also fixes Ctrl+C not terminating cancelling Haskell
programs that are stuck in hWaitForInput.
Until now, one had to force a "dirty exit" with double-Ctrl+C;
with this commit, this is no longer necessary.
Note that this commit, for the first time, makes context-switching
work in the non-threaded RTS in the presence blocking syscalls
on Windows, OSX and iOS.
I've verified these improvements on Linux, Windows, and OSX,
in both -threaded and non-threaded.
I've also added commentary in handle_tick() that explains the
reasoning behind this, as an outcome of the discussion on
To get access to the information whether or not we need to call
pthread_kill() via interruptOSThread() in the context switch timer,
that is, USE_PTHREAD_FOR_ITIMER, I had to refactor its logic into a
new file rts/Itimer.h. I also changed USE_PTHREAD_FOR_ITIMER
from a defined/undefined macro to an always-defined 1/0 macro,
so that failure to inlude the right header would result in an
error (via -Werror,-Wundef) instead of it silently being undefined
and the wrong code path being taken.
With original contribution from Nandor Licker.