Safe Haskell | None |
---|---|
Language | Haskell2010 |
Control.Monad.IOSim
Synopsis
- data IOSim s a
- type STMSim = STM
- runSim :: forall a. (forall s. IOSim s a) -> Either Failure a
- runSimOrThrow :: forall a. (forall s. IOSim s a) -> a
- runSimStrictShutdown :: forall a. (forall s. IOSim s a) -> Either Failure a
- data Failure
- runSimTrace :: forall a. (forall s. IOSim s a) -> Trace a
- runSimTraceST :: forall s a. IOSim s a -> ST s (Trace a)
- liftST :: ST s a -> IOSim s a
- traceM :: Typeable a => a -> IOSim s ()
- setCurrentTime :: UTCTime -> IOSim s ()
- unshareClock :: IOSim s ()
- data Trace a
- = Trace !Time !ThreadId !(Maybe ThreadLabel) !TraceEvent (Trace a)
- | TraceMainReturn !Time a ![LabeledThread]
- | TraceMainException !Time SomeException ![LabeledThread]
- | TraceDeadlock !Time ![LabeledThread]
- data TraceEvent
- = EventSay String
- | EventLog Dynamic
- | EventThrow SomeException
- | EventThrowTo SomeException ThreadId
- | EventThrowToBlocked
- | EventThrowToWakeup
- | EventThrowToUnmasked ThreadId
- | EventThreadForked ThreadId
- | EventThreadFinished
- | EventThreadUnhandled SomeException
- | EventTxCommitted [TVarId] [TVarId]
- | EventTxAborted
- | EventTxBlocked [TVarId]
- | EventTxWakeup [TVarId]
- | EventTimerCreated TimeoutId TVarId Time
- | EventTimerUpdated TimeoutId Time
- | EventTimerCancelled TimeoutId
- | EventTimerExpired TimeoutId
- type ThreadLabel = String
- data LabeledThread = LabeledThread {
- labeledThreadId :: ThreadId
- labeledThreadLabel :: Maybe ThreadLabel
- traceEvents :: Trace a -> [(Time, ThreadId, Maybe ThreadLabel, TraceEvent)]
- traceResult :: Bool -> Trace a -> Either Failure a
- selectTraceEvents :: (TraceEvent -> Maybe b) -> Trace a -> [b]
- selectTraceEventsDynamic :: forall a b. Typeable b => Trace a -> [b]
- selectTraceEventsSay :: Trace a -> [String]
- printTraceEventsSay :: Trace a -> IO ()
- newtype EventlogEvent = EventlogEvent String
- newtype EventlogMarker = EventlogMarker String
- execReadTVar :: TVar s a -> ST s a
- type SimM s = IOSim s
- type SimSTM = STM
Simulation monad
Instances
Run simulation
runSimOrThrow :: forall a. (forall s. IOSim s a) -> a Source #
For quick experiments and tests it is often appropriate and convenient to simply throw failures as exceptions.
runSimStrictShutdown :: forall a. (forall s. IOSim s a) -> Either Failure a Source #
Like runSim
but also fail if when the main thread terminates, there
are other threads still running or blocked. If one is trying to follow
a strict thread cleanup policy then this helps testing for that.
Simulation termination with failure
Constructors
FailureException SomeException | The main thread terminated with an exception |
FailureDeadlock | The threads all deadlocked |
FailureSloppyShutdown [LabeledThread] | The main thread terminated normally but other threads were still
alive, and strict shutdown checking was requested.
See |
Instances
Show Failure Source # | |
Exception Failure Source # | |
Defined in Control.Monad.IOSim Methods toException :: Failure -> SomeException Source # fromException :: SomeException -> Maybe Failure Source # displayException :: Failure -> String Source # |
runSimTrace :: forall a. (forall s. IOSim s a) -> Trace a Source #
See runSimTraceST
below.
runSimTraceST :: forall s a. IOSim s a -> ST s (Trace a) Source #
The most general method of running IOSim
is in ST
monad. One can
recover failures or the result from Trace
with traceResult
, or access
TraceEvent
s generated by the computation with traceEvents
. A slightly
more convenient way is exposed by runSimTrace
.
Simulation time
setCurrentTime :: UTCTime -> IOSim s () Source #
Set the current wall clock time for the thread's clock domain.
unshareClock :: IOSim s () Source #
Put the thread into a new wall clock domain, not shared with the parent thread. Changing the wall clock time in the new clock domain will not affect the other clock of other threads. All threads forked by this thread from this point onwards will share the new clock domain.
Simulation trace
Trace
is a recursive data type, it is the trace of a IOSim
computation.
The trace will contain information about thread sheduling, blocking on
TVar
s, and other internal state changes of IOSim
. More importantly it
also supports traces generated by the computation with say
(which
corresponds to using putStrLn
in IO
), traceEventM
, or dynamically typed
traces with traceM
(which generalise the base
library
traceM
)
See also: traceEvents
, traceResult
, selectTraceEvents
,
selectTraceEventsDynamic
and printTraceEventsSay
.
Constructors
Trace !Time !ThreadId !(Maybe ThreadLabel) !TraceEvent (Trace a) | |
TraceMainReturn !Time a ![LabeledThread] | |
TraceMainException !Time SomeException ![LabeledThread] | |
TraceDeadlock !Time ![LabeledThread] |
data TraceEvent Source #
Constructors
EventSay String | |
EventLog Dynamic | |
EventThrow SomeException | |
EventThrowTo SomeException ThreadId | |
EventThrowToBlocked | |
EventThrowToWakeup | |
EventThrowToUnmasked ThreadId | |
EventThreadForked ThreadId | |
EventThreadFinished | |
EventThreadUnhandled SomeException | |
EventTxCommitted [TVarId] [TVarId] | |
EventTxAborted | |
EventTxBlocked [TVarId] | |
EventTxWakeup [TVarId] | |
EventTimerCreated TimeoutId TVarId Time | |
EventTimerUpdated TimeoutId Time | |
EventTimerCancelled TimeoutId | |
EventTimerExpired TimeoutId |
Instances
Show TraceEvent Source # | |
Defined in Control.Monad.IOSim.Internal |
type ThreadLabel = String Source #
data LabeledThread Source #
Constructors
LabeledThread | |
Fields
|
Instances
Eq LabeledThread Source # | |
Defined in Control.Monad.IOSim.Internal Methods (==) :: LabeledThread -> LabeledThread -> Bool Source # (/=) :: LabeledThread -> LabeledThread -> Bool Source # | |
Ord LabeledThread Source # | |
Defined in Control.Monad.IOSim.Internal Methods compare :: LabeledThread -> LabeledThread -> Ordering Source # (<) :: LabeledThread -> LabeledThread -> Bool Source # (<=) :: LabeledThread -> LabeledThread -> Bool Source # (>) :: LabeledThread -> LabeledThread -> Bool Source # (>=) :: LabeledThread -> LabeledThread -> Bool Source # max :: LabeledThread -> LabeledThread -> LabeledThread Source # min :: LabeledThread -> LabeledThread -> LabeledThread Source # | |
Show LabeledThread Source # | |
Defined in Control.Monad.IOSim.Internal |
traceEvents :: Trace a -> [(Time, ThreadId, Maybe ThreadLabel, TraceEvent)] Source #
selectTraceEvents :: (TraceEvent -> Maybe b) -> Trace a -> [b] Source #
selectTraceEventsDynamic :: forall a b. Typeable b => Trace a -> [b] Source #
Select all the traced values matching the expected type. This relies on the sim's dynamic trace facility.
For convenience, this throws exceptions for abnormal sim termination.
selectTraceEventsSay :: Trace a -> [String] Source #
Get a trace of EventSay
.
For convenience, this throws exceptions for abnormal sim termination.
printTraceEventsSay :: Trace a -> IO () Source #
Print all EventSay
to the console.
For convenience, this throws exceptions for abnormal sim termination.
Eventlog
newtype EventlogEvent Source #
Wrapper for Eventlog events so they can be retrieved from the trace with
selectTraceEventsDynamic
.
Constructors
EventlogEvent String |
newtype EventlogMarker Source #
Wrapper for Eventlog markers so they can be retrieved from the trace with
selectTraceEventsDynamic
.
Constructors
EventlogMarker String |
Low-level API
execReadTVar :: TVar s a -> ST s a Source #