SpinCounter-0.0.1: Lock free Spin Counter

MaintainerJulian Sutherland (julian.sutherland10@imperial.ac.uk)
Safe HaskellNone



An implementation of a lock-free spin counter. Works with any monad that has atomically modificable references.



data SpinCounter r Source

A lock-free concurrent Spin counter usable in any monad, m, that is paired with a reference type, r, by an instance of MonadAtomicRef. Can use Specializations SpinCounterIO and SpinCounterSTM

type SpinCounterIO = SpinCounter IORef Source

SpinCounter inside the IO Monad.

type SpinCounterSTM = SpinCounter TVar Source

SpinCounter inside the STM Monad.

newSpinCounter :: (MonadAtomicRef r m, Integral a) => a -> m (SpinCounter r) Source

Creates a new instance of the SpinCounter data type initialized to value of the input to the function, an instance of the class Integral.

incSpinCounter :: MonadAtomicRef r m => SpinCounter r -> m () Source

Increments an instance of the SpinCounter data type by one in a lock-free manner.

readSpinCounter :: (MonadAtomicRef r m, Num a) => SpinCounter r -> m a Source

Reads the value of an instance of the SpinCounter data type in a lock-free manner.