An UnliftedMutVar# behaves like a single-element mutable array.
Moduleprimitive-unlifted-2.1.0.0Haskell2010
Data.Primitive.Unlifted.MutVar.Primops
- 1 type
- 6 values
- Packageprimitive-unlifted-2.1.0.0
- Exports7
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourcePrimops.hs
Check whether two UnliftedMutVar#es refer to the same mutable variable. This is a check on object identity, and not on contents.
casUnliftedMutVar# :: UnliftedMutVar# s aThe UnliftedMutVar# on which to operate
-> aThe expected value
-> aThe new value to install if the 'UnliftedMutVar# contains the expected value
-> State# s-> (# 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.
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.