| Copyright | (c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 Kowainik |
|---|---|
| License | MIT |
| Maintainer | Kowainik <xrom.xkov@gmail.com> |
| Stability | Stable |
| Portability | Portable |
| Safe Haskell | Safe |
| Language | Haskell2010 |
Relude.Lifted.Concurrent
Synopsis
- data MVar a
- newEmptyMVar :: MonadIO m => m (MVar a)
- newMVar :: MonadIO m => a -> m (MVar a)
- putMVar :: MonadIO m => MVar a -> a -> m ()
- readMVar :: MonadIO m => MVar a -> m a
- swapMVar :: MonadIO m => MVar a -> a -> m a
- takeMVar :: MonadIO m => MVar a -> m a
- tryPutMVar :: MonadIO m => MVar a -> a -> m Bool
- tryReadMVar :: MonadIO m => MVar a -> m (Maybe a)
- tryTakeMVar :: MonadIO m => MVar a -> m (Maybe a)
- data STM a
- atomically :: MonadIO m => STM a -> m a
- throwSTM :: Exception e => e -> STM a
- catchSTM :: Exception e => STM a -> (e -> STM a) -> STM a
- data TVar a
- newTVarIO :: MonadIO m => a -> m (TVar a)
- readTVarIO :: MonadIO m => TVar a -> m a
- modifyTVar' :: TVar a -> (a -> a) -> STM ()
- newTVar :: a -> STM (TVar a)
- readTVar :: TVar a -> STM a
- writeTVar :: TVar a -> a -> STM ()
- data TMVar a
- newTMVar :: a -> STM (TMVar a)
- newEmptyTMVar :: STM (TMVar a)
- newTMVarIO :: MonadIO m => a -> m (TMVar a)
- newEmptyTMVarIO :: MonadIO m => m (TMVar a)
- takeTMVar :: TMVar a -> STM a
- putTMVar :: TMVar a -> a -> STM ()
- readTMVar :: TMVar a -> STM a
- tryReadTMVar :: TMVar a -> STM (Maybe a)
- swapTMVar :: TMVar a -> a -> STM a
- tryTakeTMVar :: TMVar a -> STM (Maybe a)
- tryPutTMVar :: TMVar a -> a -> STM Bool
- isEmptyTMVar :: TMVar a -> STM Bool
- mkWeakTMVar :: TMVar a -> IO () -> IO (Weak (TMVar a))
MVar
An MVar (pronounced "em-var") is a synchronising variable, used
for communication between concurrent threads. It can be thought of
as a box, which may be empty or full.
Instances
| NFData1 MVar | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
| NFData (MVar a) | NOTE: Only strict in the reference and not the referenced value. Since: deepseq-1.4.2.0 |
Defined in Control.DeepSeq | |
| Eq (MVar a) | Since: base-4.1.0.0 |
newEmptyMVar :: MonadIO m => m (MVar a) Source #
Lifted to MonadIO version of newEmptyMVar.
tryPutMVar :: MonadIO m => MVar a -> a -> m Bool Source #
Lifted to MonadIO version of tryPutMVar.
tryReadMVar :: MonadIO m => MVar a -> m (Maybe a) Source #
Lifted to MonadIO version of tryReadMVar.
tryTakeMVar :: MonadIO m => MVar a -> m (Maybe a) Source #
Lifted to MonadIO version of tryTakeMVar.
STM
A monad supporting atomic memory transactions.
Instances
| Alternative STM | Takes the first non- Since: base-4.8.0.0 |
| Applicative STM | Since: base-4.8.0.0 |
| Functor STM | Since: base-4.3.0.0 |
| Monad STM | Since: base-4.3.0.0 |
| MonadPlus STM | Takes the first non- Since: base-4.3.0.0 |
| Monoid a => Monoid (STM a) | Since: base-4.17.0.0 |
| Semigroup a => Semigroup (STM a) | Since: base-4.17.0.0 |
atomically :: MonadIO m => STM a -> m a Source #
Lifted to MonadIO version of atomically.
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. If the exception is caught via catchSTM, only the changes
enclosed by the catch are rolled back; changes made outside of catchSTM
persist.
If the exception is not caught inside of the STM, it is re-thrown by
atomically, and the entire STM is rolled back.
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.
TVar
Shared memory locations that support atomic memory transactions.
readTVarIO :: MonadIO m => TVar a -> m a Source #
Lifted to MonadIO version of readTVarIO.
modifyTVar' :: TVar a -> (a -> a) -> STM () #
Strict version of modifyTVar.
Since: stm-2.3
TMVar
A TMVar is a synchronising variable, used
for communication between concurrent threads. It can be thought of
as a box, which may be empty or full.
newEmptyTMVar :: STM (TMVar a) #
Create a TMVar which is initially empty.
newTMVarIO :: MonadIO m => a -> m (TMVar a) Source #
Lifted to MonadIO version of newTMVarIO.
newEmptyTMVarIO :: MonadIO m => m (TMVar a) Source #
Lifted to MonadIO version of newEmptyTMVarIO.
tryReadTMVar :: TMVar a -> STM (Maybe a) #
A version of readTMVar which does not retry. Instead it
returns Nothing if no value is available.
Since: stm-2.3
tryTakeTMVar :: TMVar a -> STM (Maybe a) #
A version of takeTMVar that does not retry. The tryTakeTMVar
function returns Nothing if the TMVar was empty, or if
the Just aTMVar was full with contents a. After tryTakeTMVar, the
TMVar is left empty.
tryPutTMVar :: TMVar a -> a -> STM Bool #