File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Volatile modifier dependable? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Volatile modifier dependable?" Watch "Volatile modifier dependable?" New topic
Author

Volatile modifier dependable?

John Rushington
Greenhorn

Joined: Jul 01, 2002
Posts: 9
Is the volatile modifier guaranteed to work in all versions, and across all platforms that Java supports? I just assumed that since it was in the JLS, it would work, but I heard something on JavaRanch about reexamining the memory model, and want to ensure that its use won't be deprecated/isn't presently safe.
Max Habibi
town drunk
( and author)
Sheriff

Joined: Jun 27, 2002
Posts: 4118
To be brief: Nope.
HTH,
M


Java Regular Expressions
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Basically, many current implementations do not implement volatile correctly. And the keyword would be of rather limited use anyway even if it were done right - just use synchronized instead. See here and here for more details and ranting.


"I'm not back." - Bill Harding, Twister
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

It is guaranteed to work. People who make JVMs are making them to adhere to the JLS. But it does not work, and they have violated the JLS. So yes its guaranteed to work, but they have violated their guraratee.
I also agree that volatile is of limited use and their is no real use for it except for if you are communicating with a piece of hardware, or some tricky locking strategies.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Volatile modifier dependable?