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 |
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.
- newtype ModelConc n a = ModelConc {
- runModelConc :: (a -> Action n) -> Action n
- data ModelMVar n a = ModelMVar {}
- data ModelCRef n a = ModelCRef {}
- data ModelTicket a = ModelTicket {
- ticketCRef :: CRefId
- 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)
- | ANewCRef String a (ModelCRef n a -> Action n)
- | AReadCRef (ModelCRef n a) (a -> Action n)
- | AReadCRefCas (ModelCRef n a) (ModelTicket a -> Action n)
- | AModCRef (ModelCRef n a) (a -> (a, b)) (b -> Action n)
- | AModCRefCas (ModelCRef n a) (a -> (a, b)) (b -> Action n)
- | AWriteCRef (ModelCRef n a) a (Action n)
- | ACasCRef (ModelCRef 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 CRefId
- | 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 Action
s.
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.
ModelConc | |
|
An MVar
is modelled as a unique ID and a reference holding a
Maybe
value.
A CRef
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 ModelCRef
it came from,
the commits to the ModelCRef
at the time it was produced, and the
value observed.
ModelTicket | |
|
Primitive Actions
Scheduling is done in terms of a trace of Action
s. 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
.