primal-0.3.0.0: Primeval world of Haskell.
Copyright(c) Alexey Kuleshevich 2020
LicenseBSD3
MaintainerAlexey Kuleshevich <alexey@kuleshevi.ch>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Control.Prim.Concurrent

Description

 
Synopsis

Documentation

data ThreadId #

A ThreadId is an abstract type representing a handle to a thread. ThreadId is an instance of Eq, Ord and Show, where the Ord instance implements an arbitrary total ordering over ThreadIds. The Show instance lets you convert an arbitrary-valued ThreadId to string form; showing a ThreadId value is occasionally useful when debugging or diagnosing the behaviour of a concurrent program.

Note: in GHC, if you have a ThreadId, you essentially have a pointer to the thread itself. This means the thread itself can't be garbage collected until you drop the ThreadId. This misfeature will hopefully be corrected at a later date.

Constructors

ThreadId ThreadId# 

Instances

Instances details
Eq ThreadId

Since: base-4.2.0.0

Instance details

Defined in GHC.Conc.Sync

Ord ThreadId

Since: base-4.2.0.0

Instance details

Defined in GHC.Conc.Sync

Show ThreadId

Since: base-4.2.0.0

Instance details

Defined in GHC.Conc.Sync

NFData ThreadId

Since: deepseq-1.4.0.0

Instance details

Defined in Control.DeepSeq

Methods

rnf :: ThreadId -> () #

fork :: MonadUnliftPrim RW m => m () -> m ThreadId Source #

Wrapper around fork#. Unlike forkIO it does not install any exception handlers on the action, so you need make sure to do it yourself.

forkFinally :: MonadUnliftPrim RW m => m a -> (Either SomeException a -> m ()) -> m ThreadId Source #

Spawn a thread and run an action in it. Any exception raised by the new thread will be passed to the supplied exception handler, which itself will be run in a masked state

forkOn :: MonadUnliftPrim RW m => Int -> m () -> m ThreadId Source #

Wrapper around forkOn#. Unlike forkOn it does not install any exception handlers on the action, so you need make sure to do it yourself.

killThread :: MonadPrim RW m => ThreadId -> m () Source #

Wrapper around killThread#, which throws ThreadKilled exception in the target thread. Use throwTo if you want a different exception to be thrown.

yield :: forall m s. MonadPrim s m => m () Source #

Just like yield this is a Wrapper around yield# primop , except that this version works for any state token. It is safe to use within ST because it can't affect the result of computation, just the order of evaluation with respect to other threads, which is not relevant for the state thread monad anyways.

Since: 0.3.0

threadDelay :: MonadPrim RW m => Int -> m () Source #

Lifted version of threadDelay

timeout :: MonadUnliftPrim RW m => Int -> m a -> m (Maybe a) Source #

Lifted version of timeout

Since: 0.3.0

timeout_ :: MonadUnliftPrim RW m => Int -> m a -> m () Source #

Same as timeout, but ignores the outcome

Since: 0.3.0

threadIdToCInt :: ThreadId -> CInt Source #

Something that is not exported from base: convert a ThreadId to a regular integral type.

Since: 0.0.0

labelThread :: MonadPrim RW m => ThreadId -> Ptr a -> m () Source #

Pointer should refer to UTF8 encoded string of bytes

isCurrentThreadBound :: MonadPrim RW m => m Bool Source #

Check if current thread was spawned with forkOn#

Since: 0.3.0

Sparks

spark :: MonadPrim s m => a -> m a Source #

runSparks :: MonadPrim s m => m () Source #

Single threaded RTS

delay :: MonadPrim s m => Int -> m () Source #

Wrapper for delay#. Sleep specified number of microseconds. Not designed for threaded runtime: Errors when compiled with -threaded

waitRead :: MonadPrim s m => Fd -> m () Source #

Wrapper for waitRead#. Block and wait for input to become available on the Fd. Not designed for threaded runtime: Errors out when compiled with -threaded

waitWrite :: MonadPrim s m => Fd -> m () Source #

Wrapper for waitWrite#. Block and wait until output is possible on the Fd. Not designed for threaded runtime: Errors out when compiled with -threaded