I think Broadcast could be (almost) simplified to newtype Broadcast a = Broadcast { unBroadcast :: MVar a }, where "silent" is represented by an empty MVar and "broadcasting" is represented by a full MVar. listen would then just be readMVar . unBroadcast and broadcast would be putMVar x . unBroadcast. However, signal might be more difficult, since it would putMVar and then immediately takeMVar. I'm not sure if the runtime guarantees that the threads blocked on the MVar can read it before signal continues.
I think
Broadcast
could be (almost) simplified tonewtype Broadcast a = Broadcast { unBroadcast :: MVar a }
, where "silent" is represented by an emptyMVar
and "broadcasting" is represented by a fullMVar
.listen
would then just bereadMVar . unBroadcast
andbroadcast
would beputMVar x . unBroadcast
. However,signal
might be more difficult, since it wouldputMVar
and then immediatelytakeMVar
. I'm not sure if the runtime guarantees that the threads blocked on theMVar
can read it beforesignal
continues.