Re: Interview Questions



Lew wrote:
Lew wrote:
Daniel Pitts wrote:
Q: What is the affect of the volatile keyword in Java 1.5? Has it changed since 1.2?
A: In java 1.5, the a read from a volatile happens-before the write of the value that was read. This is not necessarily the semantics of volatile before 1.5.

Very summarized and, of course, completely correct.

Drat, I misread the post and misspoke. It is not completely correct. Daniel's statement is actually not at all correct. Arne's post woke me up.

A write from thread A to a volatile variable that precedes a read from thread B /happens-before/ that read, and all writes of any variables from A that preceded the write to the volatile variable from A /happen-before/ all reads of any variables from B subsequent to that read of the volatile in B.

Heh, I mis-wrote it actually. I *meant* the converse of what I wrote.
A write to a volatile happens-before the read of the value that was written.

Oops. Other than a little dyslexia, I was correct :-)

--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
.