One Of My Memory Barrier Questions
fujohnwang
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话题,你要不要⼀起来呀?^-^
这里
- 不但有及时新鲜的AI资讯和深度探讨
- 还分享AI工具、产品方法和商业机会
- 更有体系化精品付费内容等着你,加入星球(https://t.zsxq.com/0dI3ZA0sL) 即可免费领取。(加入之后一定记得看置顶消息呀!)

存量的时代,省钱就是赚钱。
在增量的时代,省钱其实是亏钱。
避坑儿是省钱的一种形式,更是真正聪明人的选择!
弯路虽然也是路,但还是能少走就少走,背后都是高昂的试错成本。
订阅「福报」,少踩坑,少走弯路,多走一步,就是不一样的胜率!
