[concurrency-interest] non-volatile vs volatile reads

Bobrowski, Maciej Maciej.Bobrowski at morganstanley.com
Thu Jun 29 09:43:23 EDT 2017

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: http://www.morganstanley.com/disclaimers  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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20170629/766f5fad/attachment.html>

More information about the Concurrency-interest mailing list