For example, if I run this code from multiple threads and each thread for many times, will there be potentially a data race?
public boolean swap(int i, int j) {
if (value.get(i) <= 0 || value.get(j) >= maxval) {
return false;
}
value.decrementAndGet(i);
value.incrementAndGet(j);
return true;
}
BTW, is there any difference if I use decrementAndGet or getAndDecrement here?
value here is an AtomicIntegerArray. I need to do performance test among different synchronization method. So I swap elemtents in value and see if the output sum the same to what is expected
My task is to find a method that "should not be DRF," but "must still be deadlock-free", and is also much faster than ReentrantLock. So I'm troubling with finding a method that has data race...