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.


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


「为AI疯狂」星球上,扶墙老师正在和朋友们讨论有趣的AI话题,你要不要⼀起来呀?^-^
这里

  1. 不但有及时新鲜的AI资讯和深度探讨
  2. 还分享AI工具、产品方法和商业机会
  3. 更有体系化精品付费内容等着你,加入星球(https://t.zsxq.com/0dI3ZA0sL) 即可免费领取。(加入之后一定记得看置顶消息呀!)

知识星球二维码

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

订阅「福报」