• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Volatile modifier dependable?

 
John Rushington
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To be brief: Nope.
HTH,
M
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic