twilight-stm-1.2: STM library with safe irrevocable I/O and inconsistency repair

Control.Concurrent.STM.Counter

Description

The Counter module implements a thread-safe integer counter. It can be used to generate unique ids in a multi-threaded system.

Synopsis

Documentation

type Counter = IORef IntSource

The counter is implemented as a simple IORef and modified atomically.

getCounter :: CounterSource

Returns a global counter.

incr :: Counter -> IO ()Source

Increments the counter.

get :: Counter -> IO IntSource

Returns the current value of the counter.

getAndIncr :: Counter -> IO IntSource

Increments the counter and returns the previous version.