• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSR-133 sent to Final Approval Ballot; question  RSS feed

 
Warren Dew
blacksmith
Ranch Hand
Posts: 1332
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was poking around in the archives regarding some Java multithreading issues I'm encountering, and clicked through to Bill Pugh's site and noticed that the final version of JSR-133 is available (dated today). You can download it at his website:

http://www.cs.umd.edu/~pugh/java/memoryModel/

Okay, now a question that I couldn't find the answer to in the archives: under the current somewhat broken memory model, can volatile variables be safely used for asynchronous communication between threads? If not, what's the right way to do this?
 
Alan Walker
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From what I have read, the consensus seems to be that a variable can safely be used for inter-thread communication if you ensure that all code accessing the variable is synchronized on the same monitor. This guarantees that the actual variable will always be used, rather than a copy in a thread's local memory.

(See, for example, "Practical Java" by Peter Haggar.)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!