当前位置:网站首页>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 :
边栏推荐
- Understanding of inverted residuals
- Ffmpeg learning notes
- 转--深入LUA脚本语言,让你彻底明白调试原理
- 转载csdn文章操作
- Origin2018 installation tutorial "recommended collection"
- Favorite transaction code management tool in SAP GUI
- mixconv代码
- Quantifiers of regular series
- [C language] detailed explanation of malloc function [easy to understand]
- SAP intelligent robot process automation (IRPA) solution sharing
猜你喜欢

思科--高可用和高可靠网络考试

vSphere+、vSAN+来了!VMware 混合云聚焦:原生、快速迁移、混合负载

2020-ViT ICLR

tcpdump命令使用详解

Digital currency: far-reaching innovation

Preparation of functional test report

447-哔哩哔哩面经1

Appium自动化测试基础 — APPium安装(一)

Appium automation test foundation - appium installation (I)

Flynk SQL client uses comparison and is familiar with official documents
随机推荐
Appium automation test foundation - appium installation (I)
SAP intelligent robot process automation (IRPA) solution sharing
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received
ESP自动下载电路设计
MySQL stored procedure
Flink SQL command line connection yarn
el-input文本域字数限制,超过显示变红并禁止输入
A few minutes before work, I found out V-model and The difference between sync
Understanding of indexes in MySQL
元宇宙可能成为互联网发展的新方向
locust的使用
Cloud Vulnerability Global Database
nn.Parameter】Pytorch特征融合自适应权重设置(可学习权重使用)
转--利用C语言中的setjmp和longjmp,来实现异常捕获和协程
Deadlock handling strategies - prevent deadlock, avoid deadlock, detect and remove deadlock
Preparation of functional test report
Happy number [fast and slow pointer of ring PROBLEMS]
Unable to climb hill sort, directly insert sort
MySQL -- index of InnoDB storage engine
思科--高可用和高可靠网络考试