atomic-primops-0.2.2.1: A safe approach to CAS and other atomic ops in Haskell.

Safe HaskellNone

Data.Atomics.Counter.Reference

Description

This reference version is implemented with atomicModifyIORef and can be a useful fallback if one of the other implementations needs to be debugged.

Synopsis

Documentation

newtype AtomicCounter Source

Constructors

AtomicCounter (IORef Int) 

newCounter :: IO AtomicCounterSource

Create a new counter initialized to zero.

readCounterForCAS :: AtomicCounter -> IO CTicketSource

Try repeatedly until we successfully increment the counter. incrCounter =

writeCounter :: AtomicCounter -> Int -> IO ()Source

Make a non-atomic write to the counter. No memory-barrier.