mei wrote:
>> Hi,
>> While reading the tutorial
>> http://java.sun.com/docs/books/tutor...ncy/index.html,
>> something caught my attention:
>> It is said that memory consistency errors can occur even when
>> atomicity of reading/writing access is guaranteed with volatile.
>> However they don't develop this matter.
>> Is there somebody that could explain me more how could this happen?
>> Thank in advance.
Knute Johnson wrote:
> I looked and couldn't find the reference you mentioned. Do you have the
> URL of the page you saw that on?
According to
<http://www-128.ibm.com/developerworks/java/library/j-jtp03304/>
"The original semantics for volatile guaranteed only that reads and writes of
volatile fields would be made directly to main memory, instead of to registers
or the local processor cache, ... In other words, this means that the old
memory model made promises only about the visibility of the variable being
read or written, and no promises about the visibility of writes to other
variables. While this was easier to implement efficiently, it turned out to be
less useful than initially thought.
"...
"The JSR 133 Expert Group decided that it would be more sensible for volatile
reads and writes not to be reorderable with any other memory operations ...
Under the new memory model, when thread A writes to a volatile variable V, and
thread B reads from V, any variable values that were visible to A at the time
that V was written are guaranteed now to be visible to B."
So it seems that what used to be is now better.
- Lew