Consider the snippet:
class Mutable {
private volatile int value;
public int get()
{
return value;
}
public int set(int value)
{
this.value = value;
}
}
class Test {
public volatile Mutable m;
}
So using the following sequence:
Thread-1: get() // returns 2
Thread-2: set(3)
Thread-1: get() // guaranteed to return 3 due to volatile with property value
But I am unable to understand the following note by the author-
one note however, when m is assigned, the internal value will be correctly visible. it is only after subsequent calls to set() which do not write m that you have problems.
Please exemplify. Which problem is he talking about?