SafeSemaphore-0.5.0: Much safer replacement for QSemN, QSem, and SampleVar

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.

Synopsis

Sample Variables

data MSampleVar a Source

Sample variables are slightly different from a normal MVar:

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.