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

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

Test.DejaFu.Conc.Internal.Threading

Contents

Description

Operations and types for threads. This module is NOT considered to form part of the public interface of this library.

Synopsis

Threads

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

Threads are stored in a map index by ThreadId.

data Thread n r Source #

All the state of a thread.

Constructors

Thread 

Fields

data BoundThread n r Source #

The state of a bound thread.

Constructors

BoundThread 

Fields

mkthread :: Action n r -> Thread n r 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 -> BlockedOn -> Bool Source #

Determine if a thread is blocked in a certain way.

Exceptions

data Handler n r Source #

An exception handler.

Constructors

Exception e => Handler (e -> MaskingState -> Action n r) 

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

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

interruptible :: Thread n r -> Bool Source #

Check if a thread can be interrupted by an exception.

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

Register a new exception handler.

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

Remove the most recent exception handler.

except :: (MaskingState -> Action n r) -> [Handler n r] -> ThreadId -> Threads n r -> Threads n r Source #

Raise an exception in a thread.

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

Set the masking state of a thread.

Manipulating threads

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

Replace the Action of a thread.

launch :: ThreadId -> ThreadId -> ((forall b. M n r b -> M n r b) -> Action n r) -> Threads n r -> Threads n r 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 b -> M n r b) -> Action n r) -> Threads n r -> Threads n r Source #

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

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

Block a thread.

wake :: BlockedOn -> Threads n r -> (Threads n r, [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.

Bound threads

makeBound :: MonadConc n => ThreadId -> Threads n r -> n (Threads n r) Source #

Turn a thread into a bound thread.

kill :: MonadConc n => ThreadId -> Threads n r -> n (Threads n r) Source #

Kill a thread and remove it from the thread map.

If the thread is bound, the worker thread is cleaned up.

runLiftedAct :: MonadConc n => ThreadId -> Threads n r -> n (Action n r) -> n (Action n r) Source #

Run an action.

If the thread is bound, the action is run in the worker thread.