static boolean unsynchronizedSetter(Date expected){
Date newDate = new Date();
AtomicReference<Date> myAtomicReference = Lookup.getAtomicRef();
boolean myStatus = myAtomicReference.compareAndSet(expected, newDate); //CAS
return myStatus;
}
Q: If 2 threads executes it, which object will get stored in the atomic reference?
In a multi-processor machine, 2 threads could be performing the CAS in the same clock cycle. Suppose they both use the same myAtomicReference object to do the CAS, both use the correct value of "expected", but they try to put in 2 distinct objects ie the 2 newDate. One of them must fail, but will myStatus be false in that thread?
I guess one hardware implementation of CompareAndSwap would make the threads queue up to do their updates. I guess even if the 2 processors are executing the CAS instruction in the same clock cycle, one of them is probably delayed.