aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/signals004.hs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/signals004.hs')
-rw-r--r--tests/signals004.hs24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/signals004.hs b/tests/signals004.hs
new file mode 100644
index 0000000..711a6eb
--- /dev/null
+++ b/tests/signals004.hs
@@ -0,0 +1,24 @@
+import Control.Concurrent
+import System.Posix
+import Control.Monad
+
+-- signal stress test: threads installing signal handlers while
+-- signals are being constantly thrown and caught.
+
+installers = 50
+sigs = 10000
+
+main = do
+ c <- newChan
+ m <- newEmptyMVar
+ installHandler sigUSR1 (handler c) Nothing
+ replicateM_ installers (forkIO $ do replicateM_ 1000 (install c); putMVar m ())
+ replicateM_ sigs (forkIO $ raiseSignal sigUSR1)
+ replicateM_ installers (takeMVar m)
+ replicateM_ sigs (readChan c)
+
+handler c = Catch (writeChan c ())
+
+install c = do
+ old <- installHandler sigUSR1 (handler c) Nothing
+ installHandler sigUSR1 old Nothing