Copyright | (c) 2016--2020 Michael Walker |
---|---|
License | MIT |
Maintainer | Michael Walker <mike@barrucadu.co.uk> |
Stability | experimental |
Portability | ExistentialQuantification, FlexibleContexts, RankNTypes |
Safe Haskell | None |
Language | Haskell2010 |
Operations and types for threads. This module is NOT considered to form part of the public interface of this library.
Synopsis
- type Threads (n :: Type -> Type) = Map ThreadId (Thread n)
- data Thread (n :: Type -> Type) = Thread {
- _continuation :: Action n
- _blocking :: Maybe BlockedOn
- _handlers :: [Handler n]
- _masking :: MaskingState
- _bound :: Maybe (BoundThread n (Action n))
- mkthread :: forall (n :: Type -> Type). Action n -> Thread n
- data BlockedOn
- (~=) :: forall (n :: Type -> Type). Thread n -> BlockedOn -> Bool
- data Handler (n :: Type -> Type) = Exception e => Handler MaskingState (e -> Action n)
- propagate :: forall (n :: Type -> Type). HasCallStack => SomeException -> ThreadId -> Threads n -> Maybe (Threads n)
- interruptible :: forall (n :: Type -> Type). Thread n -> Bool
- catching :: forall e (n :: Type -> Type). (Exception e, HasCallStack) => (e -> Action n) -> ThreadId -> Threads n -> Threads n
- uncatching :: forall (n :: Type -> Type). HasCallStack => ThreadId -> Threads n -> Threads n
- except :: forall (n :: Type -> Type). HasCallStack => MaskingState -> Action n -> [Handler n] -> ThreadId -> Threads n -> Threads n
- mask :: forall (n :: Type -> Type). HasCallStack => MaskingState -> ThreadId -> Threads n -> Threads n
- goto :: forall (n :: Type -> Type). HasCallStack => Action n -> ThreadId -> Threads n -> Threads n
- launch :: forall (n :: Type -> Type). HasCallStack => ThreadId -> ThreadId -> ((forall b. ModelConc n b -> ModelConc n b) -> Action n) -> Threads n -> Threads n
- launch' :: forall (n :: Type -> Type). HasCallStack => MaskingState -> ThreadId -> ((forall b. ModelConc n b -> ModelConc n b) -> Action n) -> Threads n -> Threads n
- block :: forall (n :: Type -> Type). HasCallStack => BlockedOn -> ThreadId -> Threads n -> Threads n
- wake :: forall (n :: Type -> Type). BlockedOn -> Threads n -> (Threads n, [ThreadId])
- makeBound :: (MonadDejaFu n, HasCallStack) => n (BoundThread n (Action n)) -> ThreadId -> Threads n -> n (Threads n)
- kill :: (MonadDejaFu n, HasCallStack) => ThreadId -> Threads n -> n (Threads n)
- runLiftedAct :: MonadDejaFu n => ThreadId -> Threads n -> n (Action n) -> n (Action n)
Threads
type Threads (n :: Type -> Type) = Map ThreadId (Thread n) Source #
Threads are stored in a map index by ThreadId
.
data Thread (n :: Type -> Type) Source #
All the state of a thread.
Thread | |
|
mkthread :: forall (n :: Type -> Type). Action n -> Thread n Source #
Construct a thread with just one action
Blocking
A BlockedOn
is used to determine what sort of variable a thread
is blocked on.
(~=) :: forall (n :: Type -> Type). Thread n -> BlockedOn -> Bool Source #
Determine if a thread is blocked in a certain way.
Exceptions
data Handler (n :: Type -> Type) Source #
An exception handler.
Exception e => Handler MaskingState (e -> Action n) |
propagate :: forall (n :: Type -> Type). HasCallStack => SomeException -> ThreadId -> Threads n -> Maybe (Threads n) Source #
Propagate an exception upwards, finding the closest handler which can deal with it.
interruptible :: forall (n :: Type -> Type). Thread n -> Bool Source #
Check if a thread can be interrupted by an exception.
catching :: forall e (n :: Type -> Type). (Exception e, HasCallStack) => (e -> Action n) -> ThreadId -> Threads n -> Threads n Source #
Register a new exception handler.
uncatching :: forall (n :: Type -> Type). HasCallStack => ThreadId -> Threads n -> Threads n Source #
Remove the most recent exception handler.
except :: forall (n :: Type -> Type). HasCallStack => MaskingState -> Action n -> [Handler n] -> ThreadId -> Threads n -> Threads n Source #
Raise an exception in a thread.
mask :: forall (n :: Type -> Type). HasCallStack => MaskingState -> ThreadId -> Threads n -> Threads n Source #
Set the masking state of a thread.
Manipulating threads
goto :: forall (n :: Type -> Type). HasCallStack => Action n -> ThreadId -> Threads n -> Threads n Source #
Replace the Action
of a thread.
launch :: forall (n :: Type -> Type). HasCallStack => ThreadId -> ThreadId -> ((forall b. ModelConc n b -> ModelConc n b) -> Action n) -> Threads n -> Threads n 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' :: forall (n :: Type -> Type). HasCallStack => MaskingState -> ThreadId -> ((forall b. ModelConc n b -> ModelConc n b) -> Action n) -> Threads n -> Threads n Source #
Start a thread with the given ID and masking state. This must not already be in use!
block :: forall (n :: Type -> Type). HasCallStack => BlockedOn -> ThreadId -> Threads n -> Threads n Source #
Block a thread.
wake :: forall (n :: Type -> Type). BlockedOn -> Threads n -> (Threads n, [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 TVar
s.
Bound threads
makeBound :: (MonadDejaFu n, HasCallStack) => n (BoundThread n (Action n)) -> ThreadId -> Threads n -> n (Threads n) Source #
Turn a thread into a bound thread.
kill :: (MonadDejaFu n, HasCallStack) => ThreadId -> Threads n -> n (Threads n) Source #
Kill a thread and remove it from the thread map.
If the thread is bound, the worker thread is cleaned up.
runLiftedAct :: MonadDejaFu n => ThreadId -> Threads n -> n (Action n) -> n (Action n) Source #
Run an action.
If the thread is bound, the action is run in the worker thread.