dejafu-0.3.0.0: Overloadable primitives for testable, potentially non-deterministic, concurrency.

Safe HaskellNone
LanguageHaskell2010

Test.DejaFu.Deterministic.Internal.Threading

Contents

Description

Operations and types for threads.

Synopsis

Threads

type Threads n r s = Map ThreadId (Thread n r s) Source

Threads are stored in a map index by ThreadId.

data Thread n r s Source

All the state of a thread.

Constructors

Thread 

Fields

_continuation :: Action n r s

The next action to execute.

_blocking :: Maybe BlockedOn

The state of any blocks.

_handlers :: [Handler n r s]

Stack of exception handlers

_masking :: MaskingState

The exception masking state.

_known :: [Either MVarId TVarId]

Shared variables the thread knows about.

_fullknown :: Bool

Whether the referenced variables of the thread are completely known. If every thread has _fullknown == True, then turn on detection of nonglobal deadlock.

mkthread :: Action n r s -> Thread n r s Source

Construct a thread with just one action

Blocking

data BlockedOn Source

A BlockedOn is used to determine what sort of variable a thread is blocked on.

Instances

(~=) :: Thread n r s -> BlockedOn -> Bool Source

Determine if a thread is blocked in a certain way.

isLocked :: ThreadId -> Threads n r a -> Bool Source

Determine if a thread is deadlocked. If at least one thread is not in a fully-known state, this will only check for global deadlock.

Exceptions

data Handler n r s Source

An exception handler.

Constructors

forall e . Exception e => Handler (e -> Action n r s) 

propagate :: SomeException -> ThreadId -> Threads n r s -> Maybe (Threads n r s) Source

Propagate an exception upwards, finding the closest handler which can deal with it.

interruptible :: Thread n r s -> Bool Source

Check if a thread can be interrupted by an exception.

catching :: Exception e => (e -> Action n r s) -> ThreadId -> Threads n r s -> Threads n r s Source

Register a new exception handler.

uncatching :: ThreadId -> Threads n r s -> Threads n r s Source

Remove the most recent exception handler.

except :: Action n r s -> [Handler n r s] -> ThreadId -> Threads n r s -> Threads n r s Source

Raise an exception in a thread.

mask :: MaskingState -> ThreadId -> Threads n r s -> Threads n r s Source

Set the masking state of a thread.

Manipulating threads

goto :: Action n r s -> ThreadId -> Threads n r s -> Threads n r s Source

Replace the Action of a thread.

launch :: ThreadId -> ThreadId -> ((forall b. M n r s b -> M n r s b) -> Action n r s) -> Threads n r s -> Threads n r s Source

Start a thread with the given ID, inheriting the masking state from the parent thread. This ID must not already be in use!

launch' :: MaskingState -> ThreadId -> ((forall b. M n r s b -> M n r s b) -> Action n r s) -> Threads n r s -> Threads n r s Source

Start a thread with the given ID and masking state. This must not already be in use!

kill :: ThreadId -> Threads n r s -> Threads n r s Source

Kill a thread.

block :: BlockedOn -> ThreadId -> Threads n r s -> Threads n r s Source

Block a thread.

wake :: BlockedOn -> Threads n r s -> (Threads n r s, [ThreadId]) Source

Unblock all threads waiting on the appropriate block. For TVar blocks, this will wake all threads waiting on at least one of the given TVars.

knows :: [Either MVarId TVarId] -> ThreadId -> Threads n r s -> Threads n r s Source

Record that a thread knows about a shared variable.

forgets :: [Either MVarId TVarId] -> ThreadId -> Threads n r s -> Threads n r s Source

Forget about a shared variable.

fullknown :: ThreadId -> Threads n r s -> Threads n r s Source

Record that a thread's shared variable state is fully known.