primitive-atomic-0.1.0.0: Wrappers for primops around atomic operations

Safe HaskellNone
LanguageHaskell2010

Data.Primitive.Array.Atomic

Synopsis

Documentation

casArray Source #

Arguments

:: PrimMonad m 
=> MutableArray (PrimState m) a

prim array

-> Int

index

-> a

expected old value

-> a

new value

-> m (Bool, a) 

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

Note that lifted values in GHC have limited guarantees concerning pointer equality. In particular, data constructor applications of single-constructor data types may be mangled by GHC Core optimizations. Users of this function are expected to understand how to make pointer equality survive GHC's optimization passes.