primitive-atomic-0.1.0.2: Wrappers for primops around atomic operations
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Primitive.Unlifted.Atomic

Synopsis

Documentation

casUnliftedArray Source #

Arguments

:: forall m a. (PrimMonad m, PrimUnlifted a) 
=> MutableUnliftedArray (PrimState m) a

array

-> Int

index

-> a

expected old value

-> a

new value

-> m (Bool, a) 

Given an array, an offset, 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.

Some unlifted types, in particular the ones that correspond to mutable resources, have good guarantees about pointer equality. With these types, this function is much easier to reason about than casArray.