JMM have guarantees that when thread A writes to volatile variable V all other (non-volatile) writes become visible to thread B after it reads that V value.
Does that guarantee holds in presence of multiple volatile V overwrites with the same value?
I.e. considering following code:
int x = 0;
int y = 0;
volatile int v = 0;
void fromThreadA() {
x = 1;
v = 0;
y = 1;
v = 0; // note that both writes to v never actually change its value
}
void fromThreadB() {
while(v == 0) {
if (x == 1 && y == 1) break;
}
}
is there guarantees that caller of fromThreadB will eventually terminate?