HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Moduleprimitive-unlifted-2.2.0.0Haskell2010

Data.Primitive.Unlifted.MutVar.Primops

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