Re: Volatile happens before question
markspace wrote:
raphfrk@gmail.com wrote:
The issue is that a read of the old value doesn't guarantee that no
update has happened.
...
Even though WA happens after RB in the synchronization ordering,
there is no relationship between R-read and W-write. The reason is
that WA and RB have no happens-before relationship.
I don't think this is quite correct. No update is in progress in your trace.
There is no happens-before between what raphfrk marked as "R-read" and
"W-write". He is quite correct.
What I think they're talking about is causality, or the idea that map.get()
No, about visibility.
might see a write from the future. That is, a write from the map.put(). I
don't see anywhere in the JLS where it says that reads can't be reordered
across this type memory barrier.
That's not different from what raphfrk said.
I'll have to dig out JCIP since at this point I think trying to read the math
heavy sections of the JLS have defeated me. The read from the future thing
kinda makes sense, since I don't recall anything that prevents it. Maybe there
is though...
Note I already mentioned this about 4 posts ago... ;-)
When there are more than one read and more than one write, you have to look at
the entire picture. Many in this conversation have made the mistake of looking
at only the first of a series of reads or writes and trying to reason about
the visible value, while ignoring later, possibly reordered actions.
Bottom line - the read from thread 2 (T2) before the write to a volatile in T1
does not impose a happens-before ("/hb/" or "<") between those two actions.
Does not. All bets are off. Done.
If the T2 read follows a different T1 write with which there is a /hb/
relationship that's a red herring.
--
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg