Chan package:concurrency
Unbounded channels.
Deviations: Chan as defined here does not have an
Eq instance, this is because the MonadConc
MVar type does not have an Eq constraint. The
deprecated unGetChan and isEmptyCHan functions are
not provided. Furthermore, the getChanContents function is
not provided as it needs unsafe I/O.
Chan is an abstract type representing an unbounded FIFO
channel.
Implements bounded channels. These channels differ from normal
Chans in that they are guaranteed to contain no more than a
certain number of elements. This is ideal when you may be writing to a
channel faster than you are able to read from it.
This module supports all the functions of
Control.Concurrent.Chan except
unGetChan and
dupChan, which are not supported for bounded channels.
Extra consistency: This version enforces that if thread Alice writes
e1 followed by e2 then e1 will be returned by readBoundedChan before
e2. Conversely, if thead Bob reads e1 followed by e2 then it was true
that writeBoundedChan e1 preceded writeBoundedChan e2.
Previous versions did not enforce this consistency: if
writeBoundedChan were preempted between putMVars or killThread arrived
between putMVars then it can fail. Similarly it might fail if
readBoundedChan were stopped after putMVar and before the second
takeMVar. An unlucky pattern of several such deaths might actually
break the invariants of the array in an unrecoverable way causing all
future reads and writes to block.
A
BoundedChan is an abstract data type representing a bounded
channel.
Deprecated: This isEmptyBoundedChan can block, no non-blocking
substitute yet
newBoundedChan n returns a channel than can contain no more
than n elements.
Read an element from the channel. If the channel is empty, this
routine will block until it is able to read. Blockers wait in a fair
FIFO queue.
A variant of
readBoundedChan which, instead of blocking when
the channel is empty, immediately returns
Nothing. Otherwise,
tryreadBoundedChan returns
Just a where
a is the element read from the channel. Note that this
routine can still block while waiting for read access to the channel.
A variant of
writeBoundedChan which, instead of blocking when
the channel is full, simply aborts and does not write the element.
Note that this routine can still block while waiting for write access
to the channel.
Write an element to the channel. If the channel is full, this routine
will block until it is able to write. Blockers wait in a fair FIFO
queue.
Write a list of elements to the channel. If the channel becomes full,
this routine will block until it can write. Competing writers may
interleave with this one.
Duplicate a
Chan: 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.
Build and returns a new instance of
Chan.
Read the next value from the
Chan.
Write an entire list of items to a
Chan.
Transactional channels
Deviations: TChan as defined here does not have an
Eq instance, this is because the MonadSTM
TVar type does not have an Eq constraint.
Furthermore, the newTChanIO and newBroadcastTChanIO
functions are not provided.
TChan is an abstract type representing an unbounded FIFO
channel.
Clone a
TChan: similar to
dupTChan, but the cloned
channel starts with the same content available as the original
channel.
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.
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.
Build and return a new instance of
TChan
Get the next value from the
TChan without removing it, retrying
if the channel is empty.
Read the next value from the
TChan.