Merge pull request #320 from barrucadu/unsafeunmask

Add unsafeUnmask to MonadConc (attempt 2)
This commit is contained in:
Michael Walker 2020-05-14 14:37:09 +01:00 committed by GitHub
commit 72b98f4f9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 115 additions and 28 deletions

View File

@ -45,10 +45,10 @@ There are a few different packages under the Déjà Fu umbrella:
| | Version | Summary |
| - | ------- | ------- |
| [concurrency][h:conc] | 1.10.0.0 | Typeclasses, functions, and data types for concurrency and STM. |
| [dejafu][h:dejafu] | 2.2.0.0 | Systematic testing for Haskell concurrency. |
| [hunit-dejafu][h:hunit] | 2.0.0.2 | Deja Fu support for the HUnit test framework. |
| [tasty-dejafu][h:tasty] | 2.0.0.3 | Deja Fu support for the Tasty test framework. |
| [concurrency][h:conc] | 1.11.0.0 | Typeclasses, functions, and data types for concurrency and STM. |
| [dejafu][h:dejafu] | 2.3.0.0 | Systematic testing for Haskell concurrency. |
| [hunit-dejafu][h:hunit] | 2.0.0.3 | Deja Fu support for the HUnit test framework. |
| [tasty-dejafu][h:tasty] | 2.0.0.4 | Deja Fu support for the Tasty test framework. |
Each package has its own README and CHANGELOG in its subdirectory.

View File

@ -6,6 +6,21 @@ standard Haskell versioning scheme.
.. _PVP: https://pvp.haskell.org/
1.11.0.0 (2020-05-14)
--------------------
* Git: :tag:`concurrency-1.11.0.0`
* Hackage: :hackage:`concurrency-1.11.0.0`
**Contributors:** :u:`mitchellwrosen` (:pull:`319`).
Added
~~~~~
* (:issue:`316`) ``Control.Monad.Conc.Class.unsafeUnmask``.
* ``Control.Monad.Conc.Class.interruptible``.
1.10.0.0 (2020-05-10)
---------------------

View File

@ -9,7 +9,7 @@
-- |
-- Module : Control.Monad.Conc.Class
-- Copyright : (c) 2016--2019 Michael Walker
-- Copyright : (c) 2016--2020 Michael Walker
-- License : MIT
-- Maintainer : Michael Walker <mike@barrucadu.co.uk>
-- Stability : experimental
@ -72,6 +72,7 @@ module Control.Monad.Conc.Class
, Ca.mask_
, uninterruptibleMask
, Ca.uninterruptibleMask_
, interruptible
-- * Mutable State
, newMVar
@ -91,7 +92,7 @@ module Control.Monad.Conc.Class
-- for the class and utilities
import Control.Exception (AsyncException(ThreadKilled),
Exception, MaskingState,
Exception, MaskingState(..),
SomeException)
import Control.Monad.Catch (MonadCatch, MonadMask,
MonadThrow)
@ -110,6 +111,7 @@ import qualified Control.Monad.STM as IO
import qualified Data.Atomics as IO
import qualified Data.IORef as IO
import qualified GHC.Conc as IO
import qualified GHC.IO as IO
-- for the transformer instances
import Control.Monad.Reader (ReaderT)
@ -154,7 +156,7 @@ import qualified Control.Monad.Writer.Strict as WS
-- Do not be put off by the use of @UndecidableInstances@, it is safe
-- here.
--
-- @since 1.10.0.0
-- @since 1.11.0.0
class ( Monad m
, MonadCatch m, MonadThrow m, MonadMask m
, MonadSTM (STM m)
@ -187,6 +189,7 @@ class ( Monad m
, atomically
, throwTo
, getMaskingState
, unsafeUnmask
#-}
-- | The associated 'MonadSTM' for this class.
@ -504,6 +507,11 @@ class ( Monad m
-- @since 1.10.0.0
getMaskingState :: m MaskingState
-- | Set the 'MaskingState' for the current thread to 'MaskedUninterruptible'.
--
-- @since 1.11.0.0
unsafeUnmask :: m a -> m a
-------------------------------------------------------------------------------
-- Utilities
@ -695,6 +703,21 @@ mask = Ca.mask
uninterruptibleMask :: MonadConc m => ((forall a. m a -> m a) -> m b) -> m b
uninterruptibleMask = Ca.uninterruptibleMask
-- | Allow asynchronous exceptions to be raised even inside 'mask',
-- making the operation interruptible.
--
-- When called outside 'mask', or inside 'uninterruptibleMask', this
-- function has no effect.
--
-- @since 1.11.0.0
interruptible :: MonadConc m => m a -> m a
interruptible act = do
st <- getMaskingState
case st of
Unmasked -> act
MaskedInterruptible -> unsafeUnmask act
MaskedUninterruptible -> act
-- Mutable Variables
-- | Create a new @MVar@ containing a value.
@ -793,6 +816,7 @@ instance MonadConc IO where
newTVarConc = IO.newTVarIO
readTVarConc = IO.readTVarIO
getMaskingState = IO.getMaskingState
unsafeUnmask = IO.unsafeUnmask
-- | Label the current thread, if the given label is nonempty.
labelMe :: String -> IO ()
@ -840,6 +864,7 @@ instance MonadConc m => MonadConc (IsConc m) where
forkOnWithUnmaskN n i ma = toIsConc (forkOnWithUnmaskN n i (\umask -> unIsConc $ ma (\mx -> toIsConc (umask $ unIsConc mx))))
forkOSWithUnmask ma = toIsConc (forkOSWithUnmask (\umask -> unIsConc $ ma (\mx -> toIsConc (umask $ unIsConc mx))))
forkOSWithUnmaskN n ma = toIsConc (forkOSWithUnmaskN n (\umask -> unIsConc $ ma (\mx -> toIsConc (umask $ unIsConc mx))))
unsafeUnmask ma = toIsConc (unsafeUnmask (unIsConc ma))
supportsBoundThreads = toIsConc supportsBoundThreads
isCurrentThreadBound = toIsConc isCurrentThreadBound
@ -923,7 +948,8 @@ instance C => MonadConc (T m) where { \
atomically = lift . atomically ; \
newTVarConc = lift . newTVarConc ; \
readTVarConc = lift . readTVarConc ; \
getMaskingState = lift getMaskingState }
getMaskingState = lift getMaskingState ; \
unsafeUnmask = liftedF F unsafeUnmask }
-- | New threads inherit the reader state of their parent, but do not
-- communicate results back.

View File

@ -2,7 +2,7 @@
-- documentation, see http://haskell.org/cabal/users-guide/
name: concurrency
version: 1.10.0.0
version: 1.11.0.0
synopsis: Typeclasses, functions, and data types for concurrency and STM.
description:
@ -19,7 +19,7 @@ license: MIT
license-file: LICENSE
author: Michael Walker
maintainer: mike@barrucadu.co.uk
copyright: (c) 2016--2019 Michael Walker
copyright: (c) 2016--2020 Michael Walker
category: Concurrency
build-type: Simple
extra-source-files: README.markdown CHANGELOG.rst
@ -32,7 +32,7 @@ source-repository head
source-repository this
type: git
location: https://github.com/barrucadu/dejafu.git
tag: concurrency-1.10.0.0
tag: concurrency-1.11.0.0
library
exposed-modules: Control.Monad.Conc.Class

View File

@ -244,6 +244,14 @@ exceptionTests = toTestList
killThread tid
readMVar y
, djfuT "Exceptions can kill masked threads which have unsafely unmasked" (gives [Left Deadlock, Right ()]) $ do
x <- newEmptyMVar
y <- newEmptyMVar
tid <- fork $ mask_ $ putMVar x () >> unsafeUnmask (putMVar y ())
readMVar x
killThread tid
readMVar y
, djfuT "Throwing to main kills the computation, if unhandled" (alwaysFailsWith isUncaughtException) $ do
tid <- myThreadId
j <- spawn $ throwTo tid Overflow

View File

@ -6,6 +6,18 @@ standard Haskell versioning scheme.
.. _PVP: https://pvp.haskell.org/
2.3.0.0 (2020-05-14)
--------------------
* Git: :tag:`dejafu-2.3.0.0`
* Hackage: :hackage:`dejafu-2.3.0.0`
Miscellaneous
~~~~~~~~~~~~~
* The version bound on :hackage:`concurrency` is >=1.11 <1.12.
2.2.0.0 (2020-05-10)
--------------------

View File

@ -141,6 +141,8 @@ instance (pty ~ Basic, Monad n) => C.MonadConc (Program pty n) where
getMaskingState = ModelConc (\c -> AGetMasking c)
unsafeUnmask ma = ModelConc (AMasking Unmasked (const ma))
-- ----------
atomically = ModelConc . AAtom

View File

@ -2,7 +2,7 @@
-- documentation, see http://haskell.org/cabal/users-guide/
name: dejafu
version: 2.2.0.0
version: 2.3.0.0
synopsis: A library for unit-testing concurrent programs.
description:
@ -20,7 +20,7 @@ license: MIT
license-file: LICENSE
author: Michael Walker
maintainer: mike@barrucadu.co.uk
copyright: (c) 2015--2019 Michael Walker
copyright: (c) 2015--2020 Michael Walker
category: Concurrency
build-type: Simple
extra-source-files: README.markdown CHANGELOG.rst
@ -33,7 +33,7 @@ source-repository head
source-repository this
type: git
location: https://github.com/barrucadu/dejafu.git
tag: dejafu-2.2.0.0
tag: dejafu-2.3.0.0
library
exposed-modules: Test.DejaFu
@ -59,7 +59,7 @@ library
-- other-modules:
-- other-extensions:
build-depends: base >=4.9 && <5
, concurrency >=1.10 && <1.11
, concurrency >=1.11 && <1.12
, containers >=0.5 && <0.7
, contravariant >=1.2 && <1.6
, deepseq >=1.1 && <2

View File

@ -27,10 +27,10 @@ There are a few different packages under the Déjà Fu umbrella:
.. csv-table::
:header: "Package", "Version", "Summary"
":hackage:`concurrency`", "1.10.0.0", "Typeclasses, functions, and data types for concurrency and STM"
":hackage:`dejafu`", "2.2.0.0", "Systematic testing for Haskell concurrency"
":hackage:`hunit-dejafu`", "2.0.0.2", "Déjà Fu support for the HUnit test framework"
":hackage:`tasty-dejafu`", "2.0.0.3", "Déjà Fu support for the tasty test framework"
":hackage:`concurrency`", "1.11.0.0", "Typeclasses, functions, and data types for concurrency and STM"
":hackage:`dejafu`", "2.3.0.0", "Systematic testing for Haskell concurrency"
":hackage:`hunit-dejafu`", "2.0.0.3", "Déjà Fu support for the HUnit test framework"
":hackage:`tasty-dejafu`", "2.0.0.4", "Déjà Fu support for the tasty test framework"
Installation

View File

@ -7,7 +7,19 @@ standard Haskell versioning scheme.
.. _PVP: https://pvp.haskell.org/
2.0.0.2 (2020-10-05)
2.0.0.3 (2020-05-10)
--------------------
* Git: :tag:`hunit-dejafu-2.0.0.3`
* Hackage: :hackage:`hunit-dejafu-2.0.0.3`
Miscellaneous
~~~~~~~~~~~~~
* The upper bound on :hackage:`dejafu` is <2.4
2.0.0.2 (2020-05-10)
--------------------
* Git: :tag:`hunit-dejafu-2.0.0.2`

View File

@ -2,7 +2,7 @@
-- documentation, see http://haskell.org/cabal/users-guide/
name: hunit-dejafu
version: 2.0.0.2
version: 2.0.0.3
synopsis: Deja Fu support for the HUnit test framework.
description:
@ -17,7 +17,7 @@ license: MIT
license-file: LICENSE
author: Michael Walker
maintainer: mike@barrucadu.co.uk
copyright: (c) 2015--2017 Michael Walker
copyright: (c) 2015--2020 Michael Walker
category: Testing
build-type: Simple
extra-source-files: README.markdown CHANGELOG.rst
@ -30,7 +30,7 @@ source-repository head
source-repository this
type: git
location: https://github.com/barrucadu/dejafu.git
tag: hunit-dejafu-2.0.0.2
tag: hunit-dejafu-2.0.0.3
library
exposed-modules: Test.HUnit.DejaFu
@ -38,7 +38,7 @@ library
-- other-extensions:
build-depends: base >=4.9 && <5
, exceptions >=0.7 && <0.11
, dejafu >=2.0 && <2.3
, dejafu >=2.0 && <2.4
, HUnit >=1.3.1 && <1.7
-- hs-source-dirs:
default-language: Haskell2010

View File

@ -7,6 +7,18 @@ standard Haskell versioning scheme.
.. _PVP: https://pvp.haskell.org/
2.0.0.4 (2020-05-14)
--------------------
* Git: :tag:`tasty-dejafu-2.0.0.4`
* Hackage: :hackage:`tasty-dejafu-2.0.0.4`
Miscellaneous
~~~~~~~~~~~~~
* The upper bound on :hackage:`dejafu` is <2.4
2.0.0.3 (2020-05-10)
--------------------

View File

@ -2,7 +2,7 @@
-- documentation, see http://haskell.org/cabal/users-guide/
name: tasty-dejafu
version: 2.0.0.3
version: 2.0.0.4
synopsis: Deja Fu support for the Tasty test framework.
description:
@ -17,7 +17,7 @@ license: MIT
license-file: LICENSE
author: Michael Walker
maintainer: mike@barrucadu.co.uk
copyright: (c) 2015--2017 Michael Walker
copyright: (c) 2015--2020 Michael Walker
category: Testing
build-type: Simple
extra-source-files: README.markdown CHANGELOG.rst
@ -30,14 +30,14 @@ source-repository head
source-repository this
type: git
location: https://github.com/barrucadu/dejafu.git
tag: tasty-dejafu-2.0.0.3
tag: tasty-dejafu-2.0.0.4
library
exposed-modules: Test.Tasty.DejaFu
-- other-modules:
-- other-extensions:
build-depends: base >=4.9 && <5
, dejafu >=2.0 && <2.3
, dejafu >=2.0 && <2.4
, random >=1.0 && <1.2
, tagged >=0.8 && <0.9
, tasty >=0.10 && <1.4