| Portability | non-portable (concurrency) |
|---|---|
| Stability | experimental |
| Maintainer | libraries@haskell.org |
| Safe Haskell | Trustworthy |
Control.Concurrent.SampleVar
Contents
Description
Deprecated: Control.Concurrent.SampleVar will be removed in GHC 7.8. Please use an alternative, e.g. the SafeSemaphore package, instead.
Sample variables
- data SampleVar a
- newEmptySampleVar :: IO (SampleVar a)
- newSampleVar :: a -> IO (SampleVar a)
- emptySampleVar :: SampleVar a -> IO ()
- readSampleVar :: SampleVar a -> IO a
- writeSampleVar :: SampleVar a -> a -> IO ()
- isEmptySampleVar :: SampleVar a -> IO Bool
Sample Variables
data SampleVar a
Sample variables are slightly different from a normal MVar:
- Reading an empty
SampleVarcauses the reader to block. (same astakeMVaron emptyMVar) - Reading a filled
SampleVarempties it and returns value. (same astakeMVar) - Writing to an empty
SampleVarfills it with a value, and potentially, wakes up a blocked reader (same as forputMVaron emptyMVar). - Writing to a filled
SampleVaroverwrites the current value. (different fromputMVaron fullMVar.)
newEmptySampleVar :: IO (SampleVar a)
Build a new, empty, SampleVar
newSampleVar :: a -> IO (SampleVar a)
Build a SampleVar with an initial value.
emptySampleVar :: SampleVar a -> IO ()
If the SampleVar is full, leave it empty. Otherwise, do nothing.
readSampleVar :: SampleVar a -> IO a
Wait for a value to become available, then take it and return.
writeSampleVar :: SampleVar a -> a -> IO ()
Write a value into the SampleVar, overwriting any previous value that
was there.
isEmptySampleVar :: SampleVar a -> IO Bool
Returns True if the SampleVar is currently empty.
Note that this function is only useful if you know that no other
threads can be modifying the state of the SampleVar, because
otherwise the state of the SampleVar may have changed by the time
you see the result of isEmptySampleVar.