dejafu-1.6.0.0: A library for unit-testing concurrent programs.

Copyright(c) 2016--2018 Michael Walker
LicenseMIT
MaintainerMichael Walker <mike@barrucadu.co.uk>
Stabilityexperimental
PortabilityFlexibleContexts, MultiWayIf, RankNTypes, RecordWildCards
Safe HaskellNone
LanguageHaskell2010

Test.DejaFu.Conc.Internal

Contents

Description

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.

Synopsis

Set-up

type SeqTrace = Seq (Decision, [(ThreadId, Lookahead)], ThreadAction) Source #

Trace but as a sequence.

data CResult n g a Source #

The result of running a concurrent program.

Constructors

CResult 

Fields

data DCSnapshot n a Source #

A snapshot of the concurrency state immediately after dontCheck finishes.

Since: 1.4.0.0

Constructors

DCSnapshot 

Fields

runConcurrency :: (MonadConc n, HasCallStack) => Bool -> Scheduler g -> MemType -> g -> IdSource -> Int -> ModelConc n a -> n (CResult n 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.

runConcurrency' :: (MonadConc n, HasCallStack) => Bool -> Scheduler g -> MemType -> Context n g -> ModelConc n a -> n (CResult n 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.

Only a separate function because ADontCheck needs it.

runConcurrencyWithSnapshot :: (MonadConc n, HasCallStack) => Scheduler g -> MemType -> Context n g -> (Threads n -> n ()) -> CRef n (Maybe (Either Failure a)) -> n (CResult n g a) Source #

Like runConcurrency but starts from a snapshot.

killAllThreads :: (MonadConc n, HasCallStack) => Context n g -> n () Source #

Kill the remaining threads

Execution

data Context n g Source #

The context a collection of threads are running in.

Constructors

Context 

runThreads :: (MonadConc n, HasCallStack) => Bool -> Scheduler g -> MemType -> CRef n (Maybe (Either Failure a)) -> Context n g -> n (CResult n g a) Source #

Run a collection of threads, until there are no threads left.

fixContext :: ThreadId -> What n g -> Context n g -> Context n g Source #

Apply the context update from stepping an action.

unblockWaitingOn :: ThreadId -> Threads n -> Threads n Source #

unblockWaitingOn tid unblocks every thread blocked in a throwTo tid.

Single-step execution

data Act Source #

What a thread did, for trace purposes.

Constructors

Single ThreadAction

Just one action.

SubC SeqTrace (Maybe (ThreadId, ThreadAction))

subconcurrency, with the given trace and final action.

Instances

Eq Act Source # 

Methods

(==) :: Act -> Act -> Bool #

(/=) :: Act -> Act -> Bool #

Show Act Source # 

Methods

showsPrec :: Int -> Act -> ShowS #

show :: Act -> String #

showList :: [Act] -> ShowS #

data What n g Source #

What a thread did, for execution purposes.

Constructors

Succeeded (Context n g)

Action succeeded: continue execution.

Failed Failure

Action caused computation to fail: stop.

Snap (Context n g)

Action was a snapshot point and we're in snapshot mode: stop.

stepThread Source #

Arguments

:: (MonadConc n, HasCallStack) 
=> 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

Action to step

-> Context n g

The execution context.

-> n (What n g, Act, Threads n -> n ()) 

Run a single thread one step, by dispatching on the type of Action.

Each case looks very similar. This is deliberate, so that the essential differences between actions are more apparent, and not hidden by accidental differences in how things are expressed.

Note: the returned snapshot action will definitely not do the right thing with relaxed memory.

stepThrow Source #

Arguments

:: (MonadConc n, Exception e) 
=> ThreadAction

Action to include in the trace.

-> ThreadId

The thread receiving the exception.

-> e

Exception to raise.

-> Context n g

The execution context.

-> n (What n g, Act, Threads n -> n ()) 

Handle an exception being thrown from an AAtom, AThrow, or AThrowTo.

synchronised Source #

Arguments

:: MonadConc n 
=> (Context n g -> n (What n g, Act, Threads n -> n ()))

Action to run after the write barrier.

-> Context n g

The original execution context.

-> n (What n g, Act, Threads n -> n ()) 

Helper for actions impose a write barrier.

dcSched :: Scheduler (Maybe Int) Source #

scheduler for ADontCheck