Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Synopsis
- atomicallyNamed :: String -> STM a -> IO a
- atomically :: STM a -> IO a
- getSTMStats :: IO (Map String (Int, Int))
- dumpSTMStats :: IO ()
- data STM a
- data TVar a
- data TArray i e
- data TBQueue a
- data TChan a
- data TMVar a
- data TQueue a
- newTChanIO :: IO (TChan a)
- newBroadcastTChanIO :: IO (TChan a)
- newTQueueIO :: IO (TQueue a)
- newTBQueueIO :: Natural -> IO (TBQueue a)
- newTMVarIO :: a -> IO (TMVar a)
- retry :: STM a
- orElse :: STM a -> STM a -> STM a
- throwSTM :: Exception e => e -> STM a
- catchSTM :: Exception e => STM a -> (e -> STM a) -> STM a
- newTVar :: a -> STM (TVar a)
- newTVarIO :: a -> IO (TVar a)
- readTVarIO :: TVar a -> IO a
- readTVar :: TVar a -> STM a
- writeTVar :: TVar a -> a -> STM ()
- registerDelay :: Int -> IO (TVar Bool)
- modifyTVar' :: TVar a -> (a -> a) -> STM ()
- newTBQueue :: Natural -> STM (TBQueue a)
- writeTBQueue :: TBQueue a -> a -> STM ()
- readTBQueue :: TBQueue a -> STM a
- tryReadTBQueue :: TBQueue a -> STM (Maybe a)
- flushTBQueue :: TBQueue a -> STM [a]
- peekTBQueue :: TBQueue a -> STM a
- tryPeekTBQueue :: TBQueue a -> STM (Maybe a)
- unGetTBQueue :: TBQueue a -> a -> STM ()
- lengthTBQueue :: TBQueue a -> STM Natural
- isEmptyTBQueue :: TBQueue a -> STM Bool
- isFullTBQueue :: TBQueue a -> STM Bool
- newTChan :: STM (TChan a)
- newBroadcastTChan :: STM (TChan a)
- writeTChan :: TChan a -> a -> STM ()
- readTChan :: TChan a -> STM a
- tryReadTChan :: TChan a -> STM (Maybe a)
- peekTChan :: TChan a -> STM a
- tryPeekTChan :: TChan a -> STM (Maybe a)
- dupTChan :: TChan a -> STM (TChan a)
- unGetTChan :: TChan a -> a -> STM ()
- isEmptyTChan :: TChan a -> STM Bool
- cloneTChan :: TChan a -> STM (TChan a)
- newTMVar :: a -> STM (TMVar a)
- newEmptyTMVar :: STM (TMVar a)
- newEmptyTMVarIO :: IO (TMVar a)
- takeTMVar :: TMVar a -> STM a
- tryTakeTMVar :: TMVar a -> STM (Maybe a)
- putTMVar :: TMVar a -> a -> STM ()
- tryPutTMVar :: TMVar a -> a -> STM Bool
- readTMVar :: TMVar a -> STM a
- tryReadTMVar :: TMVar a -> STM (Maybe a)
- swapTMVar :: TMVar a -> a -> STM a
- writeTMVar :: TMVar a -> a -> STM ()
- isEmptyTMVar :: TMVar a -> STM Bool
- mkWeakTMVar :: TMVar a -> IO () -> IO (Weak (TMVar a))
- newTQueue :: STM (TQueue a)
- writeTQueue :: TQueue a -> a -> STM ()
- readTQueue :: TQueue a -> STM a
- tryReadTQueue :: TQueue a -> STM (Maybe a)
- flushTQueue :: TQueue a -> STM [a]
- peekTQueue :: TQueue a -> STM a
- tryPeekTQueue :: TQueue a -> STM (Maybe a)
- unGetTQueue :: TQueue a -> a -> STM ()
- isEmptyTQueue :: TQueue a -> STM Bool
- modifyTVar :: TVar a -> (a -> a) -> STM ()
- stateTVar :: TVar s -> (s -> (a, s)) -> STM a
- swapTVar :: TVar a -> a -> STM a
- mkWeakTVar :: TVar a -> IO () -> IO (Weak (TVar a))
- check :: Bool -> STM ()
Documentation
atomically :: STM a -> IO a Source #
dumpSTMStats :: IO () Source #
A monad supporting atomic memory transactions.
Instances
Shared memory locations that support atomic memory transactions.
Instances
Eq (TVar a) | Since: base-4.8.0.0 |
PrimUnlifted (TVar a) | |
Defined in Data.Primitive.Unlifted.Class type Unlifted (TVar a) :: UnliftedType # toUnlifted# :: TVar a -> Unlifted (TVar a) # fromUnlifted# :: Unlifted (TVar a) -> TVar a # | |
type Unlifted (TVar a) | |
Defined in Data.Primitive.Unlifted.Class |
TArray is a transactional array, supporting the usual MArray
interface for mutable arrays.
It is currently implemented as Array ix (TVar e)
,
but it may be replaced by a more efficient implementation in the future
(the interface will remain the same, however).
Instances
MArray TArray e STM | |
Defined in Control.Concurrent.STM.TArray getBounds :: Ix i => TArray i e -> STM (i, i) # getNumElements :: Ix i => TArray i e -> STM Int newArray :: Ix i => (i, i) -> e -> STM (TArray i e) # newArray_ :: Ix i => (i, i) -> STM (TArray i e) # unsafeNewArray_ :: Ix i => (i, i) -> STM (TArray i e) unsafeRead :: Ix i => TArray i e -> Int -> STM e unsafeWrite :: Ix i => TArray i e -> Int -> e -> STM () | |
Ix i => Eq (TArray i e) | |
TBQueue
is an abstract type representing a bounded FIFO channel.
Since: stm-2.4
TChan
is an abstract type representing an unbounded FIFO channel.
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.
TQueue
is an abstract type representing an unbounded FIFO channel.
Since: stm-2.4
newTChanIO :: IO (TChan a) #
IO
version of newTChan
. This is useful for creating top-level
TChan
s using unsafePerformIO
, because using
atomically
inside unsafePerformIO
isn't
possible.
newBroadcastTChanIO :: IO (TChan a) #
IO
version of newBroadcastTChan
.
Since: stm-2.4
newTQueueIO :: IO (TQueue a) #
IO
version of newTQueue
. This is useful for creating top-level
TQueue
s using unsafePerformIO
, because using
atomically
inside unsafePerformIO
isn't
possible.
newTBQueueIO :: Natural -> IO (TBQueue a) #
IO
version of newTBQueue
. This is useful for creating top-level
TBQueue
s using unsafePerformIO
, because using
atomically
inside unsafePerformIO
isn't
possible.
newTMVarIO :: a -> IO (TMVar a) #
IO
version of newTMVar
. This is useful for creating top-level
TMVar
s using unsafePerformIO
, because using
atomically
inside unsafePerformIO
isn't
possible.
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. 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.
newTVarIO :: a -> IO (TVar a) #
IO
version of newTVar
. This is useful for creating top-level
TVar
s using unsafePerformIO
, because using
atomically
inside unsafePerformIO
isn't
possible.
readTVarIO :: TVar a -> IO a #
registerDelay :: Int -> IO (TVar Bool) #
Switch the value of returned TVar
from initial value False
to True
after a given number of microseconds. The caveats associated with
threadDelay
also apply.
Be careful not to exceed maxBound :: Int
, which on 32-bit machines is only
2147483647 μs, less than 36 minutes.
modifyTVar' :: TVar a -> (a -> a) -> STM () #
Strict version of modifyTVar
.
Since: stm-2.3
Builds and returns a new instance of TBQueue
.
writeTBQueue :: TBQueue a -> a -> STM () #
Write a value to a TBQueue
; blocks if the queue is full.
readTBQueue :: TBQueue a -> STM a #
Read the next value from the TBQueue
.
tryReadTBQueue :: TBQueue a -> STM (Maybe a) #
A version of readTBQueue
which does not retry. Instead it
returns Nothing
if no value is available.
flushTBQueue :: TBQueue a -> STM [a] #
Efficiently read the entire contents of a TBQueue
into a list. This
function never retries.
Since: stm-2.4.5
peekTBQueue :: TBQueue a -> STM a #
Get the next value from the TBQueue
without removing it,
retrying if the channel is empty.
tryPeekTBQueue :: TBQueue a -> STM (Maybe a) #
A version of peekTBQueue
which does not retry. Instead it
returns Nothing
if no value is available.
unGetTBQueue :: TBQueue a -> a -> STM () #
Put a data item back onto a channel, where it will be the next item read. Blocks if the queue is full.
isFullTBQueue :: TBQueue a -> STM Bool #
newBroadcastTChan :: STM (TChan a) #
Create a write-only TChan
. More precisely, readTChan
will retry
even after items have been written to the channel. The only way to read
a broadcast channel is to duplicate it with dupTChan
.
Consider a server that broadcasts messages to clients:
serve :: TChan Message -> Client -> IO loop serve broadcastChan client = do myChan <- dupTChan broadcastChan forever $ do message <- readTChan myChan send client message
The problem with using newTChan
to create the broadcast channel is that if
it is only written to and never read, items will pile up in memory. By
using newBroadcastTChan
to create the broadcast channel, items can be
garbage collected after clients have seen them.
Since: stm-2.4
writeTChan :: TChan a -> a -> STM () #
Write a value to a TChan
.
tryReadTChan :: TChan a -> STM (Maybe a) #
A version of readTChan
which does not retry. Instead it
returns Nothing
if no value is available.
Since: stm-2.3
peekTChan :: TChan a -> STM a #
Get the next value from the TChan
without removing it,
retrying if the channel is empty.
Since: stm-2.3
tryPeekTChan :: TChan a -> STM (Maybe a) #
A version of peekTChan
which does not retry. Instead it
returns Nothing
if no value is available.
Since: stm-2.3
dupTChan :: TChan a -> STM (TChan a) #
Duplicate a TChan
: the duplicate channel begins empty, but data written to
either channel from then on will be available from both. Hence this creates
a kind of broadcast channel, where data written by anyone is seen by
everyone else.
unGetTChan :: TChan a -> a -> STM () #
Put a data item back onto a channel, where it will be the next item read.
cloneTChan :: TChan a -> STM (TChan a) #
Clone a TChan
: similar to dupTChan, but the cloned channel starts with the
same content available as the original channel.
Since: stm-2.4
newEmptyTMVar :: STM (TMVar a) #
Create a TMVar
which is initially empty.
newEmptyTMVarIO :: IO (TMVar a) #
IO
version of newEmptyTMVar
. This is useful for creating top-level
TMVar
s using unsafePerformIO
, because using
atomically
inside unsafePerformIO
isn't
possible.
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 #
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
writeTMVar :: TMVar a -> a -> STM () #
Non-blocking write of a new value to a TMVar
Puts if empty. Replaces if populated.
writeTQueue :: TQueue a -> a -> STM () #
Write a value to a TQueue
.
readTQueue :: TQueue a -> STM a #
Read the next value from the TQueue
.
tryReadTQueue :: TQueue a -> STM (Maybe a) #
A version of readTQueue
which does not retry. Instead it
returns Nothing
if no value is available.
flushTQueue :: TQueue a -> STM [a] #
Efficiently read the entire contents of a TQueue
into a list. This
function never retries.
Since: stm-2.4.5
peekTQueue :: TQueue a -> STM a #
Get the next value from the TQueue
without removing it,
retrying if the channel is empty.
tryPeekTQueue :: TQueue a -> STM (Maybe a) #
A version of peekTQueue
which does not retry. Instead it
returns Nothing
if no value is available.
unGetTQueue :: TQueue a -> a -> STM () #
Put a data item back onto a channel, where it will be the next item read.
modifyTVar :: TVar a -> (a -> a) -> STM () #
Mutate the contents of a TVar
. N.B., this version is
non-strict.
Since: stm-2.3
stateTVar :: TVar s -> (s -> (a, s)) -> STM a #
Like modifyTVar'
but the function is a simple state transition that can
return a side value which is passed on as the result of the STM
.
Since: stm-2.5.0