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

Safe HaskellNone

Data.Atomics.Counter.IORef

Description

This version uses a boxed IORef representation, but it can be somewhat cheaper because it uses raw CAS rather than full atomicModifyIORef.

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.