HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleatomic-counter-0.1.2.4Haskell2010

Control.Concurrent.Counter.Lifted.ST

Counters that support some atomic operations. Safe to use from multiple threads and likely faster than using IORef or TVar for the same operation (terms and conditions apply).

  • 1 type
  • 10 values
datadata Counter s
#

Memory location that supports select few atomic operations.

Isomorphic to STRef s Int.

Instances1Eq
  • Eq (Counter s)Defined in atomic-counter-0.1.2.4 · Control.Concurrent.Counter.Lifted.ST

    Pointer equality

Create

1 declaration

Read/write

3 declarations
valueset :: Counter s -> Int -> ST s ()
#

Atomically assign new value to the counter.

valuecas
  1. :: Counter s
  2. -> Int

    Expected old value

  3. -> Int

    New value

  4. -> ST s Int
#

Atomic compare and swap, i.e. write the new value if the current value matches the provided old value. Returns the value of the element before the operation

Arithmetic operations

2 declarations
valueadd :: Counter s -> Int -> ST s Int
#

Atomically add an amount to the counter and return its old value.

valuesub :: Counter s -> Int -> ST s Int
#

Atomically subtract an amount from the counter and return its old value.

Bitwise operations

4 declarations
valueand :: Counter s -> Int -> ST s Int
#

Atomically combine old value with a new one via bitwise and. Returns old counter value.

valueor :: Counter s -> Int -> ST s Int
#

Atomically combine old value with a new one via bitwise or. Returns old counter value.

valuexor :: Counter s -> Int -> ST s Int
#

Atomically combine old value with a new one via bitwise xor. Returns old counter value.

valuenand :: Counter s -> Int -> ST s Int
#

Atomically combine old value with a new one via bitwise nand. Returns old counter value.