Here is a snippet from Java library:
public final boolean compareAndExchangeAcquire(boolean expectedValue, boolean newValue) {
return (int)VALUE.compareAndExchangeAcquire(this,
(expectedValue ? 1 : 0),
(newValue ? 1 : 0)) != 0;
}
It is from AtomicBoolean class. How can a cast to int return a boolean?
My main question: What is the difference between compareAndExchange vs compareAndExchangeAcquire?
In layman terms: statements written prior to xxxAcquire and after xxxRelease is free to reorder while applying xxx.
