当前位置:网站首页>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 :
边栏推荐
- Appium自动化测试基础 — APPium安装(一)
- Cloud Vulnerability Global Database
- Demo program implementation of QT version Huarui camera
- The fixed assets management subsystem reports are divided into what categories and which accounts are included
- 思科考试--路由的概念和配置考试
- Understanding of indexes in MySQL
- MySQL -- index of MyISAM storage engine
- C#/VB. Net to add text / image watermarks to PDF documents
- cvpr2022 human pose estiamtion
- 2020-ViT ICLR
猜你喜欢

Congratulations on the release of friends' new book (send welfare)

Appium自动化测试基础 — 补充:Desired Capabilities参数介绍

Quantifiers of regular series

SAP GUI 里的收藏夹事务码管理工具

Appium automation test foundation - appium installation (I)

Ffmpeg learning notes

el-input文本域字数限制,超过显示变红并禁止输入

SAP intelligent robot process automation (IRPA) solution sharing

思科考试--冗余网络

Daily question brushing record (10)
随机推荐
Cloud Vulnerability Global Database
Turn -- bring it and use it: share a gadget for checking memory leaks
locust的使用
2020-ViT ICLR
Rust语言——小小白的入门学习05
思科考试--路由的概念和配置考试
MySQL stored procedure
每日刷题记录 (十)
Cloud Vulnerability Global Database
[daily training] 326 Power of 3
104. SAP ui5 table control supports multi select and how to select multiple table row items at a time with code
Reprint CSDN article operation
Use three JS realize the 'ice cream' earth, and let the earth cool for a summer
Genicam gentl standard ver1.5 (4) Chapter 5 acquisition engine
General use of qstringlist
Turn -- go deep into Lua scripting language, so that you can thoroughly understand the debugging principle
SAP intelligent robot process automation (IRPA) solution sharing
Cut noodles C language
Deep learning -- data operation
转--原来gdb的底层调试原理这么简单