FFI: Problem with Signal Handler Interruptions

Simon Marlow marlowsd at gmail.com
Fri Aug 14 17:45:17 EDT 2009

Levi Greenspan wrote:
> Apologies for re-posting this subject here since I had sent already a
> message to haskell-café 3 days ago, but I just learned about this
> mailing list and it seems more appropriate to ask this question here I
> guess. I already got a reply from Simon Marlow but I posted some
> further (so far unanswered) questions. The thread starts here:
> http://www.haskell.org//pipermail/haskell-cafe/2009-August/064880.html.
> Basically my remaining questions are:
> 1.  How can one safely perform a blocking wait on a system call via
> FFI when compiling with -threaded and avoid signal interruptions which
> cause the call to return with EINTR?

You should check for EINTR and restart the call as necessary.  This is 
standard best practice for POSIX programming anyway, and we do it for 
all the calls that can return EINTR in the IO library and RTS.

> 2.  Could 1. be achieved by blocking SIGVTALRM in the thread doing the call?

Blocking SIGVTALRM is not a good idea: the RTS relies on the signal for 
various things.


More information about the Glasgow-haskell-users mailing list