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.Unlifted

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).

This module defines unlifted newtype wrapper and corresponding operations, they're not suitable for use with e.g. monads or being stored in other data structures that expect lifted types. For general use start with Control.Concurrent.Counter.Counter module.

  • 1 type
  • 11 values
newtypenewtype Counter s
#

Memory location that supports select few atomic operations.

Create

1 declaration

Read/write

3 declarations
valuecas :: Counter s -> Int# -> Int# -> State# s -> (# State# 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

Bitwise operations

4 declarations
valueand :: Counter s -> Int# -> State# s -> (# State# s, Int# #)
#

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

valueor :: Counter s -> Int# -> State# s -> (# State# s, Int# #)
#

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

valuexor :: Counter s -> Int# -> State# s -> (# State# s, Int# #)
#

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

valuenand :: Counter s -> Int# -> State# s -> (# State# s, Int# #)
#

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

Compare

1 declaration