signal handlers are invoked multiple times when the threaded rts is used
When you install a custom signal handler and the threaded rts is being used, then the signal handler will be invoked multiple times. Here's a program that the demonstrates this:
import Control.Concurrent import System.Posix.Signals main :: IO () main = do _ <- flip (installHandler sig) Nothing $ Catch $ putStrLn $ "Received signal " ++ show sig raiseSignal sig threadDelay 100000 where sig = sigUSR2
If you compile this with the
-threaded flag and then run it with say
+RTS -N4 then it produces the following output:
Received signal 12 Received signal 12 Received signal 12 Received signal 12 Received signal 12
In general the signal handler is invoked
n_capabilities+1 times. This also happens with all other signals.
The cause of the problem is [source:/rts/posix/Signals.c@f44bbc83bab62f9a2d25e69d87c2b4af25318d52#L256 this] loop. I don't understand why we need to write an event about the signal received in the per capability control pipe introduced by the aforementioned commit. Aren't these control pipes supposed only to be used to shutdown the capabilities (which happens [source:/rts/posix/Signals.c@f44bbc83bab62f9a2d25e69d87c2b4af25318d52#L183 here])?
Removing the loop seems to solve the issue, but I don't know if it makes #9423 (closed) reappear. I cannot test this on a Mac OS X right now.