Roger Varley wrote:
>
> any change to an instance variable
> should be synchronised. Am I missing something here?
>
This is going off topic, but the article is correct. Check
out: The Java Lanugage Specification, Second Edition, Section
17.4: "Nonatomic Treatment of double and long".
- Big main memory area, variable V=321
- Each thread has own working memory
- Thread A does a V=5 (but only in it's work area!)
- Thread B does a V=6 (but only in it's work area!)
- Big main memory area still has V=321
- Thread A and Thread B both try to move V back to main
- Who wins? If A wins, V=5, if B wins, V=6?
- Not if V is a double or long :-(
- Could be first 32 bits from A, second 32 bits from B!
- but "volatile" changes everything
Synchronization (what order operations happen in) is different
than atomicity (whether the low-level execution of operations
can interfere with other low-level ops) [1]
But synchornization is related to atomicity, in the sense
that you can use synchronization to help you get around
problems with atomicity.
But a very close reading of 17.4 is a good idea (and by
the way, if you're worried about this stuff, you don't
count as a relative newbie)
-cks
[1] Very bad incomplete unscientific definition just for
the purposes of this explanation :-)
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html