|Maintainer||Bas van Dijk <email@example.com> , Roel van Dijk <firstname.lastname@example.org>|
Broadcast is a mechanism for communication between threads. Multiple
wait until a broadcaster
a value. The listeners
block until the value is received. When the broadcaster broadcasts a value
all listeners are woken.
All functions are exception safe. Throwing asynchronous exceptions will not compromise the internal state of a broadcast.
This module is designed to be imported qualified. We suggest importing it like:
import Control.Concurrent.Broadcast ( Broadcast ) import qualified Control.Concurrent.Broadcast as Broadcast ( ... )
- data Broadcast α
- new :: IO (Broadcast α)
- newBroadcasting :: α -> IO (Broadcast α)
- listen :: Broadcast α -> IO α
- tryListen :: Broadcast α -> IO (Maybe α)
- listenTimeout :: Broadcast α -> Integer -> IO (Maybe α)
- broadcast :: Broadcast α -> α -> IO ()
- signal :: Broadcast α -> α -> IO ()
- silence :: Broadcast α -> IO ()
A broadcast is in one of two possible states:
newBroadcasting x Creates a broadcast in the "broadcasting
Listening to broadcasts
Listen to a broadcast.
- If the broadcast is "broadcasting
- If the broadcast is "silent",
listenwill block until another thread
a value to the broadcast.
Listen to a broadcast if it is available within a given amount of time.
The timeout is specified in microseconds.
If the broadcast is "silent" and a timeout of 0 μs is specified the
Nothing without blocking.
Negative timeouts are treated the same as a timeout of 0 μs.
Broadcast a value.
broadcast b x changes the state of the broadcast
b to "broadcasting
If the broadcast was "silent" all threads that are
broadcast will be woken.
Broadcast a value before becoming "silent".
The state of the broadcast is changed to "silent" after all threads that are
to the broadcast are woken and resume with the signalled value.
The semantics of signal are equivalent to the following definition: