Lie, Damn Lie and Documentation
The example to demonstrate how to use AtomicArrayExecutionObject::CompareExchange is mostly incorrect.
/// ```
/// AtomicArrayExecutionObject<vtkm::Int32, ...> arr = ...;
///
/// // Compare-exchange multiplication:
/// vtkm::Int32 current = arr->Get(idx); // Load the current value at idx
/// do {
/// vtkm::Int32 newVal = current * multFactor; // the actual multiplication
/// } while (!arr->CompareExchange(idx, ¤t, newVal));
/// ```
To begin with, arr
is not a pointer. Thus to call its Get()
method, we should use the .
operator rather than ->
.
- /// vtkm::Int32 current = arr->Get(idx); // Load the current value at idx
+ /// vtkm::Int32 current = arr.Get(idx); // Load the current value at idx
The scope of the vtkm::Int32 newVal
also ends with the closing braces }
, thus would not be accessible in the call to CompareExchange. It needs to be moved to the front of the do
keyword.
+ /// vtkm::Int32 newVal;
/// do {
- /// vtkm::Int32 newVal = current * multFactor; // the actual multiplication
+ /// newVal = current * multFactor; // the actual multiplication
/// } while (!arr->CompareExchange(idx, ¤t, newVal));
There is also some issue in the implementation of AtomicCompareExchange
that might make this an infinite loop. I will amend the issue once I investigate it further.