One Of My Memory Barrier Questions

fujohnwang

2011-10-26 One Of My Memory Barrier Questions


As JSR133’s volatile semantic description after Java5, I now get a better understanding of volatile’s half memory barrier feature.

Simple words: > If thread1 update a volatile variable and thread2 read the same volatile variable, then thread2 will also read the updates the thread1 did to other variables.

I don’t know whether my words are correct, let’s assume that’s the thing it is, so that I can continue with the question description.

Let’s say we have multiple writer threads and multiple reader threads, the writer thread will update several variables and a following volatile variable, and the reader will read the same volatile variable, then read other variables’s values, the question is, will the reader also read the updates done by all of earlier writer threads at its time point?

Here is a picture I draft to describe the scenario:


And A sample code gist:

If At Time Point 2 A reader thread can read all of the updates done by writer thread2, then will it also read all of the updates done by writer thread1 at time point 2 too? If so, what about time point3, 4, 5, etc…

My understanding is, that answer is Yes. But I am not so sure.


>>>>>> 更多阅读 <<<<<<


欢迎加入「福强私学」

跨越2190个日夜,始终坚持“实践 + 原创”打造的715125字专属知识库,囊括了(但不限于)从职场、技术、管理与商业等多个板块的内容。

  • 一个ChatGPT触达不到的地方
  • 一个带你超越AI/人工智能的地方
  • 一个与你一起成长的地方

https://afoo.me/kb.html


开天窗,拉认知,订阅「福报」,即刻拥有自己的全模态人工智能。

订阅「福报」