Copyright | (c) 2016--2018 Michael Walker |
---|---|
License | MIT |
Maintainer | Michael Walker <mike@barrucadu.co.uk> |
Stability | experimental |
Portability | MultiParamTypeClasses, RankNTypes, ScopedTypeVariables |
Safe Haskell | None |
Language | Haskell2010 |
Concurrent monads with a fixed scheduler: internal types and functions. This module is NOT considered to form part of the public interface of this library.
- type SeqTrace = Seq (Decision, [(ThreadId, Lookahead)], ThreadAction)
- data CResult n r g a = CResult {
- finalContext :: Context n r g
- finalRef :: r (Maybe (Either Failure a))
- finalRestore :: Maybe (Threads n r -> n ())
- finalTrace :: SeqTrace
- finalDecision :: Maybe (ThreadId, ThreadAction)
- data DCSnapshot r n a = DCSnapshot {
- dcsContext :: Context n r ()
- dcsRestore :: Threads n r -> n ()
- dcsRef :: r (Maybe (Either Failure a))
- runConcurrency :: (MonadConc n, MonadRef r n) => Bool -> Scheduler g -> MemType -> g -> IdSource -> Int -> M n r a -> n (CResult n r g a)
- runConcurrencyWithSnapshot :: (MonadConc n, MonadRef r n) => Scheduler g -> MemType -> Context n r g -> (Threads n r -> n ()) -> r (Maybe (Either Failure a)) -> n (CResult n r g a)
- killAllThreads :: MonadConc n => Context n r g -> n ()
- runConcurrency' :: (MonadConc n, MonadRef r n) => Bool -> Scheduler g -> MemType -> Context n r g -> M n r a -> n (CResult n r g a)
- runConcurrency'' :: (MonadConc n, MonadRef r n) => Bool -> Scheduler g -> MemType -> r (Maybe (Either Failure a)) -> Context n r g -> n (CResult n r g a)
- data Context n r g = Context {
- cSchedState :: g
- cIdSource :: IdSource
- cThreads :: Threads n r
- cWriteBuf :: WriteBuffer r
- cCaps :: Int
- runThreads :: (MonadConc n, MonadRef r n) => Bool -> Scheduler g -> MemType -> r (Maybe (Either Failure a)) -> Context n r g -> n (Context n r g, SeqTrace, Maybe (ThreadId, ThreadAction), Maybe (Threads n r -> n ()))
- data Act
- = Single ThreadAction
- | SubC SeqTrace (Maybe (ThreadId, ThreadAction))
- data What n r g
- stepThread :: forall n r g. (MonadConc n, MonadRef r n) => Bool -> Bool -> Scheduler g -> MemType -> ThreadId -> Action n r -> Context n r g -> n (What n r g, Act, Threads n r -> n ())
Execution
type SeqTrace = Seq (Decision, [(ThreadId, Lookahead)], ThreadAction) Source #
Trace
but as a sequence.
The result of running a concurrent program.
CResult | |
|
data DCSnapshot r n a Source #
A snapshot of the concurrency state immediately after dontCheck
finishes.
Since: 1.1.0.0
DCSnapshot | |
|
runConcurrency :: (MonadConc n, MonadRef r n) => Bool -> Scheduler g -> MemType -> g -> IdSource -> Int -> M n r a -> n (CResult n r g a) Source #
Run a concurrent computation with a given Scheduler
and initial
state, returning a failure reason on error. Also returned is the
final state of the scheduler, and an execution trace.
runConcurrencyWithSnapshot :: (MonadConc n, MonadRef r n) => Scheduler g -> MemType -> Context n r g -> (Threads n r -> n ()) -> r (Maybe (Either Failure a)) -> n (CResult n r g a) Source #
Like runConcurrency
but starts from a snapshot.
killAllThreads :: MonadConc n => Context n r g -> n () Source #
Kill the remaining threads
runConcurrency' :: (MonadConc n, MonadRef r n) => Bool -> Scheduler g -> MemType -> Context n r g -> M n r a -> n (CResult n r g a) Source #
Run a concurrent program using the given context, and without killing threads which remain at the end. The context must have no main thread.
runConcurrency'' :: (MonadConc n, MonadRef r n) => Bool -> Scheduler g -> MemType -> r (Maybe (Either Failure a)) -> Context n r g -> n (CResult n r g a) Source #
Like runConcurrency'
but doesn't do *ANY* set up at all.
The context a collection of threads are running in.
Context | |
|
runThreads :: (MonadConc n, MonadRef r n) => Bool -> Scheduler g -> MemType -> r (Maybe (Either Failure a)) -> Context n r g -> n (Context n r g, SeqTrace, Maybe (ThreadId, ThreadAction), Maybe (Threads n r -> n ())) Source #
Run a collection of threads, until there are no threads left.
Single-step execution
What a thread did, for trace purposes.
Single ThreadAction | Just one action. |
SubC SeqTrace (Maybe (ThreadId, ThreadAction)) |
|
What a thread did, for execution purposes.
:: (MonadConc n, MonadRef r n) | |
=> Bool | Should we record a snapshot? |
-> Bool | Is this the first action? |
-> Scheduler g | The scheduler. |
-> MemType | The memory model to use. |
-> ThreadId | ID of the current thread |
-> Action n r | Action to step |
-> Context n r g | The execution context. |
-> n (What n r g, Act, Threads n r -> n ()) |
Run a single thread one step, by dispatching on the type of
Action
.
Note: the returned snapshot action will definitely not do the right thing with relaxed memory.