| Copyright | (c) 2016--2018 Michael Walker |
|---|---|
| License | MIT |
| Maintainer | Michael Walker <mike@barrucadu.co.uk> |
| Stability | experimental |
| Portability | ExistentialQuantification, RankNTypes |
| Safe Haskell | None |
| Language | Haskell2010 |
Test.DejaFu.Conc.Internal.Common
Description
Common types and utility functions for deterministic execution of
MonadConc implementations. This module is NOT considered to form
part of the public interface of this library.
Synopsis
- newtype ModelConc n a = ModelConc {
- runModelConc :: (a -> Action n) -> Action n
- data ModelMVar n a = ModelMVar {}
- data ModelIORef n a = ModelIORef {}
- data ModelTicket a = ModelTicket {
- ticketIORef :: IORefId
- ticketWrites :: Integer
- ticketVal :: a
- data Action n
- = AFork String ((forall b. ModelConc n b -> ModelConc n b) -> Action n) (ThreadId -> Action n)
- | AForkOS String ((forall b. ModelConc n b -> ModelConc n b) -> Action n) (ThreadId -> Action n)
- | AIsBound (Bool -> Action n)
- | AMyTId (ThreadId -> Action n)
- | AGetNumCapabilities (Int -> Action n)
- | ASetNumCapabilities Int (Action n)
- | ANewMVar String (ModelMVar n a -> Action n)
- | APutMVar (ModelMVar n a) a (Action n)
- | ATryPutMVar (ModelMVar n a) a (Bool -> Action n)
- | AReadMVar (ModelMVar n a) (a -> Action n)
- | ATryReadMVar (ModelMVar n a) (Maybe a -> Action n)
- | ATakeMVar (ModelMVar n a) (a -> Action n)
- | ATryTakeMVar (ModelMVar n a) (Maybe a -> Action n)
- | ANewIORef String a (ModelIORef n a -> Action n)
- | AReadIORef (ModelIORef n a) (a -> Action n)
- | AReadIORefCas (ModelIORef n a) (ModelTicket a -> Action n)
- | AModIORef (ModelIORef n a) (a -> (a, b)) (b -> Action n)
- | AModIORefCas (ModelIORef n a) (a -> (a, b)) (b -> Action n)
- | AWriteIORef (ModelIORef n a) a (Action n)
- | ACasIORef (ModelIORef n a) (ModelTicket a) a ((Bool, ModelTicket a) -> Action n)
- | Exception e => AThrow e
- | Exception e => AThrowTo ThreadId e (Action n)
- | Exception e => ACatching (e -> ModelConc n a) (ModelConc n a) (a -> Action n)
- | APopCatching (Action n)
- | AMasking MaskingState ((forall b. ModelConc n b -> ModelConc n b) -> ModelConc n a) (a -> Action n)
- | AResetMask Bool Bool MaskingState (Action n)
- | AAtom (ModelSTM n a) (a -> Action n)
- | ALift (n (Action n))
- | AYield (Action n)
- | ADelay Int (Action n)
- | AReturn (Action n)
- | ACommit ThreadId IORefId
- | AStop (n ())
- | ASub (ModelConc n a) (Either Failure a -> Action n)
- | AStopSub (Action n)
- | ADontCheck (Maybe Int) (ModelConc n a) (a -> Action n)
- lookahead :: Action n -> Lookahead
The ModelConc Monad
newtype ModelConc n a Source #
The underlying monad is based on continuations over Actions.
One might wonder why the return type isn't reflected in Action,
and a free monad formulation used. This would remove the need for a
AStop actions having their parameter. However, this makes the
current expression of threads and exception handlers very difficult
(perhaps even not possible without significant reworking), so I
abandoned the attempt.
Constructors
| ModelConc | |
Fields
| |
An MVar is modelled as a unique ID and a reference holding a
Maybe value.
data ModelIORef n a Source #
A IORef is modelled as a unique ID and a reference holding
thread-local values, the number of commits, and the most recent
committed value.
data ModelTicket a Source #
A Ticket is modelled as the ID of the ModelIORef it came from,
the commits to the ModelIORef at the time it was produced, and the
value observed.
Constructors
| ModelTicket | |
Fields
| |
Primitive Actions
Scheduling is done in terms of a trace of Actions. Blocking can
only occur as a result of an action, and they cover (most of) the
primitives of the concurrency. spawn is absent as it is
implemented in terms of newEmptyMVar, fork, and putMVar.
Constructors