compareAndExchange method
Atomically sets the value of the element at the given index to the newValue
if the current value equals the expectedValue and returns the old value of the element in any case.
Implementation
external T compareAndExchange(Int index, T expectedValue, T newValue);