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-primops-0.8.8Haskell2010

Data.Atomics.Internal

This module provides only the raw primops (and necessary types) for atomic operations.

  • 1 type
  • 6 values
valuecasIntArray#
  1. :: MutableByteArray# d
  2. -> Int#
  3. -> Int#
  4. -> Int#
  5. -> State# d
  6. -> (# State# d, Int# #)
#

Given an array, an offset in machine words, the expected old value, and the new value, perform an 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. Implies a full memory barrier.

newtypenewtype Ticket a
#

When performing compare-and-swaps, the ticket encapsulates proof that a thread observed a specific previous value of a mutable variable. It is provided in lieu of the "old" value to compare-and-swap.

Design note: Tickets exist to hide objects from the GHC compiler, which can normally perform many optimizations that change pointer equality. A Ticket, on the other hand, is a first-class object that can be handled by the user, but will not have its pointer identity changed by compiler optimizations (but will of course, change addresses during garbage collection).

Instances2Eq, Show
  • Eq (Ticket a)Defined in atomic-primops-0.8.8 · Data.Atomics.Internal
  • Show (Ticket a)Defined in atomic-primops-0.8.8 · Data.Atomics.Internal

Very unsafe, not to be used

1 declaration