Treiber-0.0.3: Lock free Treiber stack

MaintainerJulian Sutherland (
Safe HaskellNone



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



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, Eq a) => 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.

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

Pushes an element on to a Treiber stack.

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

Pops an element of a Treiber stack. Returns Nothing if the stack is empty.