Copyright | (c) Alexey Kuleshevich 2020 |
---|---|
License | BSD3 |
Maintainer | Alexey Kuleshevich <[email protected]> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Control.Prim.Concurrent
Contents
Description
Synopsis
- data ThreadId = ThreadId ThreadId#
- fork :: MonadUnliftPrim RW m => m () -> m ThreadId
- forkFinally :: MonadUnliftPrim RW m => m a -> (Either SomeException a -> m ()) -> m ThreadId
- forkOn :: MonadUnliftPrim RW m => Int -> m () -> m ThreadId
- forkOnFinally :: MonadUnliftPrim RW m => Int -> m a -> (Either SomeException a -> m ()) -> m ThreadId
- forkOS :: MonadUnliftPrim RW m => m () -> m ThreadId
- killThread :: MonadPrim RW m => ThreadId -> m ()
- yield :: forall m s. MonadPrim s m => m ()
- threadDelay :: MonadPrim RW m => Int -> m ()
- timeout :: MonadUnliftPrim RW m => Int -> m a -> m (Maybe a)
- timeout_ :: MonadUnliftPrim RW m => Int -> m a -> m ()
- myThreadId :: MonadPrim RW m => m ThreadId
- threadIdToCInt :: ThreadId -> CInt
- threadStatus :: MonadPrim RW m => ThreadId -> m ThreadStatus
- labelThread :: MonadPrim RW m => ThreadId -> Ptr a -> m ()
- isCurrentThreadBound :: MonadPrim RW m => m Bool
- threadCapability :: MonadPrim RW m => ThreadId -> m (Int, Bool)
- getNumCapabilities :: MonadPrim RW m => m Int
- setNumCapabilities :: MonadPrim RW m => Int -> m ()
- spark :: MonadPrim s m => a -> m a
- numSparks :: MonadPrim s m => m Int
- runSparks :: MonadPrim s m => m ()
- delay :: MonadPrim s m => Int -> m ()
- waitRead :: MonadPrim s m => Fd -> m ()
- waitWrite :: MonadPrim s m => Fd -> m ()
- module Control.Prim.Monad
Documentation
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
ThreadId
s. 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.
Instances
Eq ThreadId | Since: base-4.2.0.0 |
Ord ThreadId | Since: base-4.2.0.0 |
Defined in GHC.Conc.Sync | |
Show ThreadId | Since: base-4.2.0.0 |
NFData ThreadId | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq |
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
forkOnFinally :: MonadUnliftPrim RW m => Int -> m a -> (Either SomeException a -> m ()) -> m ThreadId Source #
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
myThreadId :: MonadPrim RW m => m ThreadId Source #
Wrapper around myThreadId#
.
threadIdToCInt :: ThreadId -> CInt Source #
Something that is not exported from base
: convert a ThreadId
to a regular
integral type.
Since: 0.0.0
threadStatus :: MonadPrim RW m => ThreadId -> m ThreadStatus Source #
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
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
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
module Control.Prim.Monad