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
writeSampleVar to hang. The
MSampleVar in this module is immune
to this error, and has a simpler implementation.
Sample variables are slightly different from a normal
- Reading an empty
MSampleVarcauses the reader to block. (same as
- Reading a filled
MSampleVarempties it and returns value. (same as
- Try reading a filled
MSampleVarreturns a Maybe value. (same as
- Writing to an empty
MSampleVarfills it with a value, and potentially, wakes up a blocked reader (same as for
- Writing to a filled
MSampleVaroverwrites the current value. (different from
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.