Control.Concurrent.MSampleVar
Contents
Description
MSampleVar is a safer version of the Control.Concurrent.SampleVar in
base. The same problem as QSem(N) is being fixed, that of handling waiters
that die before being woken normally. For Control.Concurrent.SampleVar in
base this error can lead to thinking a full SampleVar is really empty and
cause writeSampleVar to hang. The MSampleVar in this module is immune
to this error, and has a simpler implementation.
- data MSampleVar a
- newEmptySV :: IO (MSampleVar a)
- newSV :: a -> IO (MSampleVar a)
- emptySV :: MSampleVar a -> IO ()
- readSV :: MSampleVar a -> IO a
- writeSV :: MSampleVar a -> a -> IO ()
- isEmptySV :: MSampleVar a -> IO Bool
Sample Variables
data MSampleVar a Source
Sample variables are slightly different from a normal MVar:
- Reading an empty
MSampleVarcauses the reader to block. (same astakeMVaron emptyMVar) - Reading a filled
MSampleVarempties it and returns value. (same astakeMVar) - Try reading a filled
MSampleVarreturns a Maybe value. (same astryTakeMVar) - Writing to an empty
MSampleVarfills it with a value, and potentially, wakes up a blocked reader (same as forputMVaron emptyMVar). - Writing to a filled
MSampleVaroverwrites the current value. (different fromputMVaron fullMVar.)
newEmptySV :: IO (MSampleVar a)Source
newSV :: a -> IO (MSampleVar a)Source
emptySV :: MSampleVar a -> IO ()Source
If the MSampleVar is full, leave it empty. Otherwise, do nothing.
emptySV can block and be interrupted, in which case it does nothing. If
emptySV returns then it left the MSampleVar in an empty state.
readSV :: MSampleVar a -> IO aSource
Wait for a value to become available, then take it and return.
readSV can block and be interrupted, in which case it takes nothing. If
'readSV returns normally then it has taken a value.
writeSV :: MSampleVar a -> a -> IO ()Source
Write a value into the MSampleVar, overwriting any previous value that was
there.
writeSV can block and be interrupted, in which case it does nothing.
isEmptySV :: MSampleVar a -> IO BoolSource