Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- concurrently :: MonadUnliftIO m => m a -> m b -> m (a, b)
- concurrently_ :: MonadUnliftIO m => m a -> m b -> m ()
- race :: MonadUnliftIO m => m a -> m b -> m (Either a b)
- race_ :: MonadUnliftIO m => m a -> m b -> m ()
- mapConcurrently :: (MonadUnliftIO m, Traversable t) => (a -> m b) -> t a -> m (t b)
- mapConcurrently_ :: (MonadUnliftIO m, Foldable f) => (a -> m b) -> f a -> m ()
- forConcurrently :: (MonadUnliftIO m, Traversable t) => t a -> (a -> m b) -> m (t b)
- forConcurrently_ :: (MonadUnliftIO m, Foldable f) => f a -> (a -> m b) -> m ()
- replicateConcurrently :: MonadUnliftIO m => Int -> m a -> m [a]
- replicateConcurrently_ :: MonadUnliftIO m => Int -> m a -> m ()
- newtype Concurrently (m :: * -> *) a = Concurrently {
- runConcurrently :: m a
- data Async a
- async :: MonadUnliftIO m => m a -> m (Async a)
- asyncBound :: MonadUnliftIO m => m a -> m (Async a)
- asyncOn :: MonadUnliftIO m => Int -> m a -> m (Async a)
- asyncWithUnmask :: MonadUnliftIO m => ((forall b. m b -> m b) -> m a) -> m (Async a)
- asyncOnWithUnmask :: MonadUnliftIO m => Int -> ((forall b. m b -> m b) -> m a) -> m (Async a)
- cancel :: MonadIO m => Async a -> m ()
- uninterruptibleCancel :: MonadIO m => Async a -> m ()
- cancelWith :: (Exception e, MonadIO m) => Async a -> e -> m ()
- withAsync :: MonadUnliftIO m => m a -> (Async a -> m b) -> m b
- withAsyncBound :: MonadUnliftIO m => m a -> (Async a -> m b) -> m b
- withAsyncOn :: MonadUnliftIO m => Int -> m a -> (Async a -> m b) -> m b
- withAsyncWithUnmask :: MonadUnliftIO m => ((forall c. m c -> m c) -> m a) -> (Async a -> m b) -> m b
- withAsyncOnWithUnmask :: MonadUnliftIO m => Int -> ((forall c. m c -> m c) -> m a) -> (Async a -> m b) -> m b
- wait :: MonadIO m => Async a -> m a
- waitSTM :: Async a -> STM a
- waitCatch :: MonadIO m => Async a -> m (Either SomeException a)
- waitCatchSTM :: Async a -> STM (Either SomeException a)
- waitAny :: MonadIO m => [Async a] -> m (Async a, a)
- waitAnySTM :: [Async a] -> STM (Async a, a)
- waitAnyCatch :: MonadIO m => [Async a] -> m (Async a, Either SomeException a)
- waitAnyCatchSTM :: [Async a] -> STM (Async a, Either SomeException a)
- waitAnyCancel :: MonadIO m => [Async a] -> m (Async a, a)
- waitAnyCatchCancel :: MonadIO m => [Async a] -> m (Async a, Either SomeException a)
- waitEither :: MonadIO m => Async a -> Async b -> m (Either a b)
- waitEitherSTM :: Async a -> Async b -> STM (Either a b)
- waitEither_ :: MonadIO m => Async a -> Async b -> m ()
- waitEitherSTM_ :: Async a -> Async b -> STM ()
- waitEitherCatch :: MonadIO m => Async a -> Async b -> m (Either (Either SomeException a) (Either SomeException b))
- waitEitherCatchSTM :: Async a -> Async b -> STM (Either (Either SomeException a) (Either SomeException b))
- waitEitherCancel :: MonadIO m => Async a -> Async b -> m (Either a b)
- waitEitherCatchCancel :: MonadIO m => Async a -> Async b -> m (Either (Either SomeException a) (Either SomeException b))
- waitBoth :: MonadIO m => Async a -> Async b -> m (a, b)
- waitBothSTM :: Async a -> Async b -> STM (a, b)
- poll :: MonadIO m => Async a -> m (Maybe (Either SomeException a))
- pollSTM :: Async a -> STM (Maybe (Either SomeException a))
- link :: MonadIO m => Async a -> m ()
- link2 :: MonadIO m => Async a -> Async b -> m ()
- asyncThreadId :: Async a -> ThreadId
- compareAsyncs :: Async a -> Async b -> Ordering
- data ExceptionInLinkedThread where
- data AsyncCancelled = AsyncCancelled
- forkIO :: MonadUnliftIO m => m () -> m ThreadId
- forkWithUnmask :: MonadUnliftIO m => ((forall a. m a -> m a) -> m ()) -> m ThreadId
- forkOn :: MonadUnliftIO m => Int -> m () -> m ThreadId
- forkOnWithUnmask :: MonadUnliftIO m => Int -> ((forall a. m a -> m a) -> m ()) -> m ThreadId
- forkFinally :: MonadUnliftIO m => m a -> (Either SomeException a -> m ()) -> m ThreadId
- throwTo :: (Exception e, MonadIO m) => ThreadId -> e -> m ()
- killThread :: MonadIO m => ThreadId -> m ()
- data STM a
- atomically :: MonadIO m => STM a -> m a
- retry :: STM a
- throwSTM :: Exception e => e -> STM a
- catchSTM :: Exception e => STM a -> (e -> STM a) -> STM a
- unsafeIOToSTM :: IO a -> STM a
- threadDelay :: MonadIO m => Int -> m ()
- registerDelay :: MonadIO m => Int -> m (TVar Bool)
- yield :: MonadIO m => m ()
- data ThreadId
- myThreadId :: MonadIO m => m ThreadId
- mkWeakThreadId :: MonadIO m => ThreadId -> m (Weak ThreadId)
- data ThreadStatus
- data BlockReason
- threadStatus :: ThreadId -> IO ThreadStatus
- threadCapability :: MonadIO m => ThreadId -> m (Int, Bool)
- labelThread :: ThreadId -> String -> IO ()
- threadWaitRead :: MonadIO m => Fd -> m ()
- threadWaitReadSTM :: Fd -> IO (STM (), IO ())
- threadWaitWrite :: MonadIO m => Fd -> m ()
- threadWaitWriteSTM :: Fd -> IO (STM (), IO ())
- closeFdWith :: (Fd -> IO ()) -> Fd -> IO ()
- module Concurrency.IORef
- module Concurrency.MVar
- module Concurrency.TVar
- module Concurrency.TMVar
Concurrency
High-level concurrency
concurrently :: MonadUnliftIO m => m a -> m b -> m (a, b) #
Unlifted concurrently
.
Since: unliftio-0.1.0.0
concurrently_ :: MonadUnliftIO m => m a -> m b -> m () #
Unlifted concurrently_
.
Since: unliftio-0.1.0.0
race :: MonadUnliftIO m => m a -> m b -> m (Either a b) #
Unlifted race
.
Since: unliftio-0.1.0.0
race_ :: MonadUnliftIO m => m a -> m b -> m () #
Unlifted race_
.
Since: unliftio-0.1.0.0
mapConcurrently :: (MonadUnliftIO m, Traversable t) => (a -> m b) -> t a -> m (t b) #
Unlifted mapConcurrently
.
Since: unliftio-0.1.0.0
mapConcurrently_ :: (MonadUnliftIO m, Foldable f) => (a -> m b) -> f a -> m () #
Unlifted mapConcurrently_
.
Since: unliftio-0.1.0.0
forConcurrently :: (MonadUnliftIO m, Traversable t) => t a -> (a -> m b) -> m (t b) #
Unlifted forConcurrently
.
Since: unliftio-0.1.0.0
forConcurrently_ :: (MonadUnliftIO m, Foldable f) => f a -> (a -> m b) -> m () #
Unlifted forConcurrently_
.
Since: unliftio-0.1.0.0
replicateConcurrently :: MonadUnliftIO m => Int -> m a -> m [a] #
Unlifted replicateConcurrently
.
Since: unliftio-0.1.0.0
replicateConcurrently_ :: MonadUnliftIO m => Int -> m a -> m () #
Unlifted replicateConcurrently_
.
Since: unliftio-0.1.0.0
newtype Concurrently (m :: * -> *) a #
Unlifted Concurrently
.
Since: unliftio-0.1.0.0
Concurrently | |
|
Instances
Low-level concurrency using async
An asynchronous action spawned by async
or withAsync
.
Asynchronous actions are executed in a separate thread, and
operations are provided for waiting for asynchronous actions to
complete and obtaining their results (see e.g. wait
).
async :: MonadUnliftIO m => m a -> m (Async a) #
Unlifted async
.
Since: unliftio-0.1.0.0
asyncBound :: MonadUnliftIO m => m a -> m (Async a) #
Unlifted asyncBound
.
Since: unliftio-0.1.0.0
asyncWithUnmask :: MonadUnliftIO m => ((forall b. m b -> m b) -> m a) -> m (Async a) #
Unlifted asyncWithUnmask
.
Since: unliftio-0.1.0.0
asyncOnWithUnmask :: MonadUnliftIO m => Int -> ((forall b. m b -> m b) -> m a) -> m (Async a) #
Unlifted asyncOnWithUnmask
.
Since: unliftio-0.1.0.0
uninterruptibleCancel :: MonadIO m => Async a -> m () #
Lifted uninterruptibleCancel
.
Since: unliftio-0.1.0.0
cancelWith :: (Exception e, MonadIO m) => Async a -> e -> m () #
Lifted cancelWith
. Additionally uses toAsyncException
to
ensure async exception safety.
Since: unliftio-0.1.0.0
withAsync :: MonadUnliftIO m => m a -> (Async a -> m b) -> m b #
Unlifted withAsync
.
Since: unliftio-0.1.0.0
withAsyncBound :: MonadUnliftIO m => m a -> (Async a -> m b) -> m b #
Unlifted withAsyncBound
.
Since: unliftio-0.1.0.0
withAsyncOn :: MonadUnliftIO m => Int -> m a -> (Async a -> m b) -> m b #
Unlifted withAsyncOn
.
Since: unliftio-0.1.0.0
withAsyncWithUnmask :: MonadUnliftIO m => ((forall c. m c -> m c) -> m a) -> (Async a -> m b) -> m b #
Unlifted withAsyncWithUnmask
.
Since: unliftio-0.1.0.0
withAsyncOnWithUnmask :: MonadUnliftIO m => Int -> ((forall c. m c -> m c) -> m a) -> (Async a -> m b) -> m b #
Unlifted withAsyncOnWithMask
.
Since: unliftio-0.1.0.0
waitCatch :: MonadIO m => Async a -> m (Either SomeException a) #
Lifted waitCatch
.
Since: unliftio-0.1.0.0
waitCatchSTM :: Async a -> STM (Either SomeException a) #
A version of waitCatch
that can be used inside an STM transaction.
waitAnySTM :: [Async a] -> STM (Async a, a) #
A version of waitAny
that can be used inside an STM transaction.
Since: async-2.1.0
waitAnyCatch :: MonadIO m => [Async a] -> m (Async a, Either SomeException a) #
Lifted waitAnyCatch
.
Since: unliftio-0.1.0.0
waitAnyCatchSTM :: [Async a] -> STM (Async a, Either SomeException a) #
A version of waitAnyCatch
that can be used inside an STM transaction.
Since: async-2.1.0
waitAnyCancel :: MonadIO m => [Async a] -> m (Async a, a) #
Lifted waitAnyCancel
.
Since: unliftio-0.1.0.0
waitAnyCatchCancel :: MonadIO m => [Async a] -> m (Async a, Either SomeException a) #
Lifted waitAnyCatchCancel
.
Since: unliftio-0.1.0.0
waitEither :: MonadIO m => Async a -> Async b -> m (Either a b) #
Lifted waitEither
.
Since: unliftio-0.1.0.0
waitEitherSTM :: Async a -> Async b -> STM (Either a b) #
A version of waitEither
that can be used inside an STM transaction.
Since: async-2.1.0
waitEither_ :: MonadIO m => Async a -> Async b -> m () #
Lifted waitEither_
.
Since: unliftio-0.1.0.0
waitEitherSTM_ :: Async a -> Async b -> STM () #
A version of waitEither_
that can be used inside an STM transaction.
Since: async-2.1.0
waitEitherCatch :: MonadIO m => Async a -> Async b -> m (Either (Either SomeException a) (Either SomeException b)) #
Lifted waitEitherCatch
.
Since: unliftio-0.1.0.0
waitEitherCatchSTM :: Async a -> Async b -> STM (Either (Either SomeException a) (Either SomeException b)) #
A version of waitEitherCatch
that can be used inside an STM transaction.
Since: async-2.1.0
waitEitherCancel :: MonadIO m => Async a -> Async b -> m (Either a b) #
Lifted waitEitherCancel
.
Since: unliftio-0.1.0.0
waitEitherCatchCancel :: MonadIO m => Async a -> Async b -> m (Either (Either SomeException a) (Either SomeException b)) #
Lifted waitEitherCatchCancel
.
Since: unliftio-0.1.0.0
waitBothSTM :: Async a -> Async b -> STM (a, b) #
A version of waitBoth
that can be used inside an STM transaction.
Since: async-2.1.0
poll :: MonadIO m => Async a -> m (Maybe (Either SomeException a)) #
Lifted poll
.
Since: unliftio-0.1.0.0
pollSTM :: Async a -> STM (Maybe (Either SomeException a)) #
A version of poll
that can be used inside an STM transaction.
data ExceptionInLinkedThread where #
Instances
Show ExceptionInLinkedThread | |
Defined in Control.Concurrent.Async showsPrec :: Int -> ExceptionInLinkedThread -> ShowS # show :: ExceptionInLinkedThread -> String # showList :: [ExceptionInLinkedThread] -> ShowS # | |
Exception ExceptionInLinkedThread | |
data AsyncCancelled #
The exception thrown by cancel
to terminate a thread.
Instances
Eq AsyncCancelled | |
Defined in Control.Concurrent.Async (==) :: AsyncCancelled -> AsyncCancelled -> Bool # (/=) :: AsyncCancelled -> AsyncCancelled -> Bool # | |
Show AsyncCancelled | |
Defined in Control.Concurrent.Async showsPrec :: Int -> AsyncCancelled -> ShowS # show :: AsyncCancelled -> String # showList :: [AsyncCancelled] -> ShowS # | |
Exception AsyncCancelled | |
Defined in Control.Concurrent.Async |
Lower-level concurrency using forkIO
forkIO :: MonadUnliftIO m => m () -> m ThreadId #
Unlifted version of forkIO
.
Since: unliftio-0.1.1.0
forkWithUnmask :: MonadUnliftIO m => ((forall a. m a -> m a) -> m ()) -> m ThreadId #
Unlifted version of forkIOWithUnmask
.
Since: unliftio-0.1.1.0
forkOn :: MonadUnliftIO m => Int -> m () -> m ThreadId #
Unlifted version of forkOn
.
Since: unliftio-0.1.1.0
forkOnWithUnmask :: MonadUnliftIO m => Int -> ((forall a. m a -> m a) -> m ()) -> m ThreadId #
Unlifted version of forkOnWithUnmask
.
Since: unliftio-0.1.1.0
forkFinally :: MonadUnliftIO m => m a -> (Either SomeException a -> m ()) -> m ThreadId #
Unlifted version of forkFinally
.
Since: unliftio-0.1.1.0
throwTo :: (Exception e, MonadIO m) => ThreadId -> e -> m () #
Throw an asynchronous exception to another thread.
Synchronously typed exceptions will be wrapped into an
AsyncExceptionWrapper
, see
https://github.com/fpco/safe-exceptions#determining-sync-vs-async.
It's usually a better idea to use the UnliftIO.Async module, see https://github.com/fpco/safe-exceptions#quickstart.
Since: unliftio-0.1.0.0
killThread :: MonadIO m => ThreadId -> m () #
Lifted version of killThread
.
Since: unliftio-0.1.1.0
STM
A monad supporting atomic memory transactions.
Instances
Monad STM | Since: base-4.3.0.0 |
Functor STM | Since: base-4.3.0.0 |
Applicative STM | Since: base-4.8.0.0 |
Alternative STM | Since: base-4.8.0.0 |
MonadPlus STM | Since: base-4.3.0.0 |
MonadCatch STM | |
MonadThrow STM | |
Defined in Control.Monad.Catch | |
Pointed STM | |
Defined in Data.Pointed | |
MonadBase STM STM | |
Defined in Control.Monad.Base |
atomically :: MonadIO m => STM a -> m a #
Lifted version of atomically
Since: unliftio-0.2.1.0
Retry execution of the current memory transaction because it has seen
values in TVar
s which mean that it should not continue (e.g. the TVar
s
represent a shared buffer that is now empty). The implementation may
block the thread until one of the TVar
s that it has read from has been
updated. (GHC only)
throwSTM :: Exception e => e -> STM a #
A variant of throw
that can only be used within the STM
monad.
Throwing an exception in STM
aborts the transaction and propagates the
exception.
Although throwSTM
has a type that is an instance of the type of throw
, the
two functions are subtly different:
throw e `seq` x ===> throw e throwSTM e `seq` x ===> x
The first example will cause the exception e
to be raised,
whereas the second one won't. In fact, throwSTM
will only cause
an exception to be raised when it is used within the STM
monad.
The throwSTM
variant should be used in preference to throw
to
raise an exception within the STM
monad because it guarantees
ordering with respect to other STM
operations, whereas throw
does not.
unsafeIOToSTM :: IO a -> STM a #
Unsafely performs IO in the STM monad. Beware: this is a highly dangerous thing to do.
- The STM implementation will often run transactions multiple times, so you need to be prepared for this if your IO has any side effects.
- The STM implementation will abort transactions that are known to
be invalid and need to be restarted. This may happen in the middle
of
unsafeIOToSTM
, so make sure you don't acquire any resources that need releasing (exception handlers are ignored when aborting the transaction). That includes doing any IO using Handles, for example. Getting this wrong will probably lead to random deadlocks. - The transaction may have seen an inconsistent view of memory when
the IO runs. Invariants that you expect to be true throughout
your program may not be true inside a transaction, due to the
way transactions are implemented. Normally this wouldn't be visible
to the programmer, but using
unsafeIOToSTM
can expose it.
Delay
threadDelay :: MonadIO m => Int -> m () #
Lifted version of threadDelay
.
Since: unliftio-0.1.1.0
registerDelay :: MonadIO m => Int -> m (TVar Bool) #
Lifted version of registerDelay
Since: unliftio-0.2.1.0
Cooperative concurrency
Thread info
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 |
Hashable ThreadId | |
Defined in Data.Hashable.Class | |
NFData ThreadId | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
PrimUnlifted ThreadId | Since: primitive-0.6.4.0 |
Defined in Data.Primitive.UnliftedArray toArrayArray# :: ThreadId -> ArrayArray# # fromArrayArray# :: ArrayArray# -> ThreadId # |
myThreadId :: MonadIO m => m ThreadId #
Lifted version of myThreadId
.
Since: unliftio-0.1.1.0
mkWeakThreadId :: MonadIO m => ThreadId -> m (Weak ThreadId) #
Lifted version of mkWeakThreadId
.
Since: unliftio-0.1.1.0
data ThreadStatus #
The current status of a thread
ThreadRunning | the thread is currently runnable or running |
ThreadFinished | the thread has finished |
ThreadBlocked BlockReason | the thread is blocked on some resource |
ThreadDied | the thread received an uncaught exception |
Instances
Eq ThreadStatus | |
Defined in GHC.Conc.Sync (==) :: ThreadStatus -> ThreadStatus -> Bool # (/=) :: ThreadStatus -> ThreadStatus -> Bool # | |
Ord ThreadStatus | |
Defined in GHC.Conc.Sync compare :: ThreadStatus -> ThreadStatus -> Ordering # (<) :: ThreadStatus -> ThreadStatus -> Bool # (<=) :: ThreadStatus -> ThreadStatus -> Bool # (>) :: ThreadStatus -> ThreadStatus -> Bool # (>=) :: ThreadStatus -> ThreadStatus -> Bool # max :: ThreadStatus -> ThreadStatus -> ThreadStatus # min :: ThreadStatus -> ThreadStatus -> ThreadStatus # | |
Show ThreadStatus | |
Defined in GHC.Conc.Sync showsPrec :: Int -> ThreadStatus -> ShowS # show :: ThreadStatus -> String # showList :: [ThreadStatus] -> ShowS # |
data BlockReason #
BlockedOnMVar | blocked on |
BlockedOnBlackHole | blocked on a computation in progress by another thread |
BlockedOnException | blocked in |
BlockedOnSTM | blocked in |
BlockedOnForeignCall | currently in a foreign call |
BlockedOnOther | blocked on some other resource. Without |
Instances
Eq BlockReason | |
Defined in GHC.Conc.Sync (==) :: BlockReason -> BlockReason -> Bool # (/=) :: BlockReason -> BlockReason -> Bool # | |
Ord BlockReason | |
Defined in GHC.Conc.Sync compare :: BlockReason -> BlockReason -> Ordering # (<) :: BlockReason -> BlockReason -> Bool # (<=) :: BlockReason -> BlockReason -> Bool # (>) :: BlockReason -> BlockReason -> Bool # (>=) :: BlockReason -> BlockReason -> Bool # max :: BlockReason -> BlockReason -> BlockReason # min :: BlockReason -> BlockReason -> BlockReason # | |
Show BlockReason | |
Defined in GHC.Conc.Sync showsPrec :: Int -> BlockReason -> ShowS # show :: BlockReason -> String # showList :: [BlockReason] -> ShowS # |
threadStatus :: ThreadId -> IO ThreadStatus #
threadCapability :: MonadIO m => ThreadId -> m (Int, Bool) #
Lifted version of threadCapability
.
Since: unliftio-0.1.1.0
labelThread :: ThreadId -> String -> IO () #
labelThread
stores a string as identifier for this thread if
you built a RTS with debugging support. This identifier will be used in
the debugging output to make distinction of different threads easier
(otherwise you only have the thread state object's address in the heap).
Other applications like the graphical Concurrent Haskell Debugger
(http://www.informatik.uni-kiel.de/~fhu/chd/) may choose to overload
labelThread
for their purposes as well.
File descriptor blocking
threadWaitRead :: MonadIO m => Fd -> m () #
Lifted version of threadWaitRead
.
Since: unliftio-0.1.1.0
threadWaitReadSTM :: Fd -> IO (STM (), IO ()) #
Returns an STM action that can be used to wait for data to read from a file descriptor. The second returned value is an IO action that can be used to deregister interest in the file descriptor.
threadWaitWrite :: MonadIO m => Fd -> m () #
Lifted version of threadWaitWrite
.
Since: unliftio-0.1.1.0
threadWaitWriteSTM :: Fd -> IO (STM (), IO ()) #
Returns an STM action that can be used to wait until data can be written to a file descriptor. The second returned value is an IO action that can be used to deregister interest in the file descriptor.
:: (Fd -> IO ()) | Low-level action that performs the real close. |
-> Fd | File descriptor to close. |
-> IO () |
Close a file descriptor in a concurrency-safe way (GHC only). If
you are using threadWaitRead
or threadWaitWrite
to perform
blocking I/O, you must use this function to close file
descriptors, or blocked threads may not be woken.
Any threads that are blocked on the file descriptor via
threadWaitRead
or threadWaitWrite
will be unblocked by having
IO exceptions thrown.
Re-exports
module Concurrency.IORef
module Concurrency.MVar
module Concurrency.TVar
module Concurrency.TMVar