Moduleconcurrent-extra-0.7.0.12Haskell98
Control.Concurrent.Broadcast
A Broadcast is a mechanism for communication between threads. Multiple
listeners wait until a broadcaster broadcasts 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 ( ... )
- 1 type
- 8 values
- Packageconcurrent-extra-0.7.0.12
- Exports9
- LanguageHaskell98
- LicenceBSD-3-Clause
- SourceBroadcast.hs
Creating broadcasts
2 declarationsnew creates a broadcast in the "silent" state.
newBroadcasting x creates a broadcast in the "broadcasting x" state.
Listening to broadcasts
3 declarationsListen to a broadcast.
If the broadcast is "broadcasting
x",listenwill returnximmediately.If the broadcast is "silent",
listenwill block until another threadbroadcastsa value to the broadcast.
Listen to a broadcast if it is available within a given amount of time.
Like listen, but with a timeout. A return value of Nothing indicates a timeout occurred.
The timeout is specified in microseconds.
If the broadcast is "silent" and a timeout of 0 μs is specified the function returns Nothing without blocking.
Negative timeouts are treated the same as a timeout of 0 μs.
Broadcasting
3 declarationsBroadcast a value.
broadcast b x changes the state of the broadcast b to "broadcasting x".
If the broadcast was "silent" all threads that are listening to the
broadcast will be woken.
Broadcast a value before becoming "silent".
The state of the broadcast is changed to "silent" after all threads that are
listening to the broadcast are woken and resume with the signalled value.
The semantics of signal are equivalent to the following definition:
signal b x = block $ broadcast b x >> silence b
Set a broadcast to the "silent" state.