SIGALRM, SIGVTALRM, and third party libraries

Simon Marlow marlowsd at gmail.com
Mon Sep 6 05:53:55 EDT 2010


On 03/09/2010 22:00, Bryan O'Sullivan wrote:
> I spent some time this morning trying to use HDBC-mysql to talk to a
> database. It uses the C mysql bindings, which talks over a blocking
> socket to the database server. Not surprisingly, it fails reliably when
> the thread it's running in is hit by an RTS-initiated alarm signal.
>
> I've managed to make the code *appear* to work successfully with some
> hacking:
>
>     * Run in a bound thread
>     * Use pthread_sigmask to temporarily block SIGALRM and SIGVTALRM to
>       *only* this thread while issuing the sensitive native calls
>     * Profit?
 >
> What I am wondering is if there's a practical downside to doing this. Am
> I going to accidentally kill something? This is a very important gap in
> the usability of GHC with native libraries, and if this approach
> actually turns out to be safe in practice, that would be wonderful.

I think that should be fine - there should always be a worker thread in 
the system available to handle the signal.  You could probably block 
those signals permanently for that thread.

But why does the failure occur in the first place?  Is the library not 
handling EINTR?

Cheers,
	Simon


More information about the Glasgow-haskell-users mailing list