static boolean unsynchronizedSetter(Date expected){
Date newDate = new Date();
AtomicReference<Date> myAtomicReference = Lookup.getAtomicRef();
boolean myStatus = myAtomicReference.compareAndSet(expected, newDate);
return myStatus;
}
Q: If 2 threads are running, which object will be stored in the reference link?
In a multiprocessor machine, 2 threads can execute CAS in a single clock cycle. Suppose they both use the same myAtomicReference object to execute CAS, both use the correct "expected" value, but they try to put two different objects, that is, 2 newDate. One of them should fail, but will myStatus be false in this thread?
I assume that one hardware implementation of CompareAndSwap will force the thread queue to perform its updates. I think that even if 2 processors execute the CAS instruction in one clock cycle, one of them is probably delayed.