summaryrefslogtreecommitdiff
path: root/libraries/base/tests
diff options
context:
space:
mode:
authorFacundo Domínguez <facundo.dominguez@tweag.io>2015-10-19 18:16:55 +0200
committerBen Gamari <ben@smart-cactus.org>2015-10-19 18:17:03 +0200
commit2b25a589ae8f6364bf086b4878f5ec26954931d3 (patch)
tree26f6084b3a9ca383e1ec269e3ad17450d8d863c3 /libraries/base/tests
parent7bbb61bc969c27a38b26a605d5ac70ac98c328d9 (diff)
downloadhaskell-2b25a589ae8f6364bf086b4878f5ec26954931d3.tar.gz
base: Have the argument of mask restore the state.
The implementation of `mask` and `uninterruptibleMask` assumed so far that the restore argument would be called in a context with the same masking state as that set by `mask` or `uninterruptibleMask`. This patch has the restore argument restore the masking, whatever the current masking state is. Test Plan: validate Reviewers: simonmar, hvr, austin, bgamari Reviewed By: bgamari Subscribers: thomie, qnikst Differential Revision: https://phabricator.haskell.org/D1327 GHC Trac Issues: #10149
Diffstat (limited to 'libraries/base/tests')
-rw-r--r--libraries/base/tests/T10149.hs19
-rw-r--r--libraries/base/tests/T10149.stdout4
-rw-r--r--libraries/base/tests/all.T1
3 files changed, 24 insertions, 0 deletions
diff --git a/libraries/base/tests/T10149.hs b/libraries/base/tests/T10149.hs
new file mode 100644
index 0000000000..d15b0d766a
--- /dev/null
+++ b/libraries/base/tests/T10149.hs
@@ -0,0 +1,19 @@
+import Control.Concurrent
+import Control.Exception
+
+main :: IO ()
+main = do
+ mask $ \unmask -> mask $ \restore ->
+ unmask $ restore $ getMaskingState >>= print
+ uninterruptibleMask $ \unmask -> uninterruptibleMask $ \restore ->
+ unmask $ restore $ getMaskingState >>= print
+
+ mv <- newEmptyMVar
+ mask_ $ -- start with exceptions masked
+ mask $ \restore -> forkIOWithUnmask $ \unmask -> unmask $
+ restore $ getMaskingState >>= print >> putMVar mv ()
+ takeMVar mv
+ uninterruptibleMask_ $ -- start with exceptions uninterruptibly masked
+ uninterruptibleMask $ \restore -> forkIOWithUnmask $ \unmask -> unmask $
+ restore $ getMaskingState >>= print >> putMVar mv ()
+ takeMVar mv
diff --git a/libraries/base/tests/T10149.stdout b/libraries/base/tests/T10149.stdout
new file mode 100644
index 0000000000..f78328dd88
--- /dev/null
+++ b/libraries/base/tests/T10149.stdout
@@ -0,0 +1,4 @@
+MaskedInterruptible
+MaskedUninterruptible
+MaskedInterruptible
+MaskedUninterruptible
diff --git a/libraries/base/tests/all.T b/libraries/base/tests/all.T
index f53ad0cb80..00b653b64e 100644
--- a/libraries/base/tests/all.T
+++ b/libraries/base/tests/all.T
@@ -209,3 +209,4 @@ test('T9848',
, only_ways(['normal'])],
compile_and_run,
['-O'])
+test('T10149',normal, compile_and_run,[''])