Treiber-0.0.4: Lock free Treiber stack

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

Data.NonBlocking.LockFree.Treiber

Description

An implementation of Treiber stacks, a lock free stack. Works with any monad that has atomically modificable references.

Synopsis

Documentation

data TreiberStack r a Source

A lock-free concurrent Treiber stack usable in any Monad, m, that is paired with a reference type, r, by an instance of MonadAtomicRef. Can use Specializations TreiberStackIO and TreiberStackSTM.

type TreiberStackIO a = TreiberStack IORef a Source

TreiberStack inside the IO Monad.

type TreiberStackSTM a = TreiberStack TVar a Source

TreiberStack inside the STM Monad.

newTreiberStack :: MonadAtomicRef r m => m (TreiberStack r a) Source

Creates a new empty instance of the TreiberStack. Internally implemented with a reference of type r, which is why they must be atomically modifiable. Initially empty.

pushTreiberStack :: MonadAtomicRef r m => TreiberStack r a -> a -> m () Source

Pushes an element on to a TreiberStack in a lock-free manner.

popTreiberStack :: MonadAtomicRef r m => TreiberStack r a -> m (Maybe a) Source

Pops an element of a TreiberStack in a lock-free manner. Returns Nothing if the stack is empty.