当前位置:网站首页>Explain the volatile keyword
Explain the volatile keyword
2022-07-01 22:55:00 【Keyboard singer】
One 、 brief introduction
1.Volatile Memory semantics
1. When you write a volatile variable ,JMM The shared variable value in the local memory corresponding to the thread will be immediately refreshed back to the main memory .
2. When reading a volatile variable ,JMM Will set the local memory corresponding to this thread to be invalid , Go back to main memory and read the latest shared variable .
3. therefore volatile The write memory semantics of is to refresh directly into main memory , The memory semantics of reading is to read directly from main memory .
2. Two characteristics
1. visibility : Flush back to main memory immediately after writing and send notification in time , You can go to the main memory to get the latest version , The previous changes are visible to all subsequent threads !
2. Prohibit command rearrangement : Reordering is a means by which compiler and processor reorder instruction sequences in order to optimize program performance , Sometimes it will change the sequence of program statements . There is no data dependency , You can reorder ; There is a data dependency , No reordering . But the rearranged instructions can never change the original serial semantics ! This must be taken into account in concurrent design !
3. The above prohibition of instruction rearrangement is based on memory barrier :
Roughly divided into two kinds
1. Reading barrier : Insert a read barrier before reading instructions , Let working memory or CPU The cached data in the cache is invalid , Go back to jade memory to get the latest data .
2. Write barriers : Insert a write barrier after writing instructions , Force data written to the buffer to be flushed back to main memory .
stay Java Level of Unsafe Classes have the following native Method :
边栏推荐
- Origin2018 installation tutorial "recommended collection"
- What class loading mechanisms does the JVM have?
- twenty million two hundred and twenty thousand seven hundred and one
- Deadlock handling strategies - prevent deadlock, avoid deadlock, detect and remove deadlock
- rxjs Observable of 操作符的单步调试分析
- Resttemplate remote call tool class
- General use of qstringlist
- 每日刷题记录 (十)
- Understanding of transactions in MySQL
- 人体姿态估计的热图变成坐标点的两种方案
猜你喜欢
Favorite transaction code management tool in SAP GUI
MySQL5.7 设置密码策略(等保三级密码改造)
陈天奇的机器学习编译课(免费)
Use three JS realize the 'ice cream' earth, and let the earth cool for a summer
分享一个一年经历两次裁员的程序员的一些感触
使用 Three.js 实现'雪糕'地球,让地球也凉爽一夏
Cutefishos system~
el-input文本域字数限制,超过显示变红并禁止输入
思科--高可用和高可靠网络考试
3DE resources have nothing or nothing wrong
随机推荐
Demo program implementation of QT version Huarui camera
Cutefishos system~
Mixconv code
Efficiency improvement - encourage personalized container development environment
[target tracking] | single target tracking indicator
3DE resources have nothing or nothing wrong
死锁的处理策略—预防死锁、避免死锁、检测和解除死锁
MySQL view exercise
Appium automated testing foundation - Supplement: introduction to desired capabilities parameters
nn.Parameter】Pytorch特征融合自适应权重设置(可学习权重使用)
Réimpression de l'article csdn
Rust language - Introduction to Xiaobai 05
Configure filter
cvpr2022 human pose estiamtion
pytorch训练自己网络后可视化特征图谱的代码
rxjs Observable of 操作符的单步调试分析
Electron学习(三)之简单交互操作
Kubernetes create service access pod
ECMAScript 2022 正式发布,有你了解过的吗?
mixconv代码