FFI: Problem with Signal Handler Interruptions

Levi Greenspan greenspan.levi at googlemail.com
Sat Aug 8 19:02:10 EDT 2009


Hi Bulat,

On Fri, Aug 7, 2009 at 5:32 PM, Bulat
Ziganshin<bulat.ziganshin at gmail.com> wrote:
> Hello Levi,
>
> Friday, August 7, 2009, 6:48:42 PM, you wrote:
>
>> 1.  How can one safely perform a blocking wait on a system call via
>> FFI when compiling with -threaded
>
> i think you should use forkOS to create OS thread dedicated to Haskell
> thread

Yes, but that wouldn't help me with my problem of getting signal
interruptions. Simon Marlow wrote in the haskell-café thread:
"The SIGVTALRM signal is delivered to one (random) thread in the
program [...]" [1]

>> and avoid signal interruptions which cause the call to return with EINTR?
>
> don't know, but may be you can retry on this retcode or disable EINTR in one
> specific OS thread

Yes, currently I use throwErrnoIfMinus1Retry from Foreign.C.Error, but
I am not sure if this is the recommended way. Seeing

...
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigaction(SIGCHLD, NULL, {SIG_DFL}, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
nanosleep({3, 0}, 0xbfad005c)           = ? ERESTART_RESTARTBLOCK (To
be restarted)
--- SIGVTALRM (Virtual timer expired) @ 0 (0) ---
sigreturn()                             = ? (mask now [])
...

many times in the output of strace made me slightly uneasy. So right
now I have two options which *seem* to work ok. One is to retry on
EINTR, and the other to block SIGVTALRM as described in [2]. But am
still unsure whether (i) this is correct and recommended, and (ii)
there is no better option.

Cheers,
Levi

---
[1] http://www.haskell.org//pipermail/haskell-cafe/2009-August/064971.html
[2] http://www.haskell.org//pipermail/haskell-cafe/2009-August/065023.html


More information about the Glasgow-haskell-users mailing list