License | BSD3 |
---|---|

Maintainer | Julian Sutherland (julian.sutherland10@imperial.ac.uk) |

Safe Haskell | None |

Language | Haskell98 |

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

- data TreiberStack r a
- type TreiberStackIO a = TreiberStack IORef a
- type TreiberStackSTM a = TreiberStack TVar a
- newTreiberStack :: MonadAtomicRef r m => m (TreiberStack r a)
- pushTreiberStack :: MonadAtomicRef r m => TreiberStack r a -> a -> m ()
- popTreiberStack :: MonadAtomicRef r m => TreiberStack r a -> m (Maybe a)

# 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

type TreiberStackSTM a = TreiberStack TVar a Source

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.