Detailed semantics of volatile regarding timeliness of visibility

Viewed 1166

Consider a volatile int sharedVar. We know that the JLS gives us the following guarantees:

  1. every action of a writing thread w preceding its write of value i to sharedVar in program order happens-before the write action;
  2. the write of value i by w happens-before the successful read of i from sharedVar by a reading thread r;
  3. the successful read of i from sharedVar by the reading thread r happens-before all subsequent actions of r in 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.

5 Answers
Related