concurrent-extra-0.3.1: Extra concurrency primitives

MaintainerBas van Dijk <> , Roel van Dijk <>



A Broadcast variable is a mechanism for communication between threads. Multiple reader threads can wait until a broadcaster thread writes a signal. The readers retry until the signal is received. When the broadcaster sends the signal all readers are woken.

This module is designed to be imported qualified. We suggest importing it like:

 import           Control.Concurrent.STM.Broadcast ( Broadcast )
 import qualified Control.Concurrent.STM.Broadcast as Broadcast ( ... )



data Broadcast α Source

A broadcast variable. It can be thought of as a box, which may be empty of full.


new :: STM (Broadcast α)Source

Create a new empty Broadcast variable.

newWritten :: α -> STM (Broadcast α)Source

Create a new Broadcast variable containing an initial value.

read :: Broadcast α -> STM αSource

Read the value of a Broadcast variable.

If the Broadcast variable contains a value it will be returned immediately, otherwise it will retry until another thread writes a value to the Broadcast variable.

tryRead :: Broadcast α -> STM (Maybe α)Source

Try to read the value of a Broadcast variable; non blocking.

Like read but doesn't retry. Returns Just the contents of the Broadcast if it wasn't empty, Nothing otherwise.

write :: Broadcast α -> α -> STM ()Source

Write a new value into a Broadcast variable.

If the variable is empty any threads that are reading from the variable will be woken. If the variable is full its contents will simply be overwritten.

clear :: Broadcast α -> STM ()Source

Clear the contents of a Broadcast variable.