Consider a volatile int sharedVar. We know that the JLS gives us the following guarantees:
- every action of a writing thread
wpreceding its write of valueitosharedVarin program orderhappens-beforethe write action; - the write of value
ibywhappens-beforethe successful read ofifromsharedVarby a reading threadr; - the successful read of
ifromsharedVarby the reading threadrhappens-beforeall subsequent actions ofrin program order.
However, there is still no wall-clock time guarantee given as to when the reading thread will observe the value i. An implementation that simply never lets the reading thread see that value still complies with this contract.
I have thought about this for a while and I can't see any loopholes, but I assume there must be. Please, point out the loophole in my reasoning.