non-volatile vs volatile reads

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

non-volatile vs volatile reads

Bobrowski, Maciej

Let’s consider the class:




   int x = 0;

   volatile int y = 0;


  void write(int newVal) {

     x = newVal;

     y = newVal;




Let’s assume one writer calls write(1) , potentially multiple times.


I understand that result of calling just foo.x is not defined under JMM (it could be 0, it could be 1). However:


foo.y // this returns 1



According to the full-fence characteristics of volatile read, foo.x is guaranteed to be 1. How is this achieved? Let’s assume x is on a different cache-line or is stored in local registers?

NOTICE: Morgan Stanley is not acting as a municipal advisor and the opinions or views contained herein are not intended to be, and do not constitute, advice within the meaning of Section 975 of the Dodd-Frank Wall Street Reform and Consumer Protection Act. If you have received this communication in error, please destroy all electronic and paper copies and notify the sender immediately. Mistransmission is not intended to waive confidentiality or privilege. Morgan Stanley reserves the right, to the extent permitted under applicable law, to monitor electronic communications. This message is subject to terms available at the following link:  If you cannot access these links, please notify us by reply message and we will send the contents to you. By communicating with Morgan Stanley you consent to the foregoing and to the voice recording of conversations with personnel of Morgan Stanley.

Concurrency-interest mailing list
[hidden email]