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

Moduleprimitive-unlifted-2.1.0.0Haskell2010

Data.Primitive.Unlifted.MutVar.Primops

  • 1 type
  • 6 values
valuecasUnliftedMutVar#
  1. :: UnliftedMutVar# s a

    The UnliftedMutVar# on which to operate

  2. -> a

    The expected value

  3. -> a

    The new value to install if the 'UnliftedMutVar# contains the expected value

  4. -> State# s
  5. -> (# State# s, Int#, a #)
#

Performs a machine-level compare and swap (CAS) operation on an UnliftedMutVar#. Returns a tuple containing an Int# which is '1#' when a swap is performed, along with the most "current" value from the UnliftedMutVar#. This return value can be used as the expected value if a CAS loop is required, though it may be better to get a fresh read. Note that this behavior differs from the more common CAS behavior, which is to return the old value before the CAS occured.

valueatomicSwapUnliftedMutVar#
  1. :: UnliftedMutVar# s a
  2. -> a
  3. -> State# s
  4. -> (# State# s, a #)
#

Atomically replace the value in an UnliftedMutVar# with the given one, returning the old value.

Implementation note: this really should be a GHC primop, because it is supported very efficiently in hardware, but unfortunately it's not (yet), so we implement it as a CAS loop.