当前位置:网站首页>"Ask every day" what is volatile
"Ask every day" what is volatile
2022-07-25 14:52:00 【Senior fishing Engineer】
Memory semantics
volatile Write : When you write a volatile Variable time ,JMM All shared variables in the local memory of this thread will be flushed to the main memory . Be careful , It's all , Not just volatile Variable
volatile read : When reading a volatile Variable time ,JMM The local memory of this thread will be set as invalid , Then read the shared variables from main memory .
If the above two steps are taken together , The reading thread is reading a volatile Variable time , The writing thread is writing this volatile All operations on shared variables before variables will immediately become visible to the reader thread .
Implementation of memory semantics
I said before , Reordering is divided into compiler and processor rearrangement . In order to achieve volatile What about the semantics of ,JMM Will limit these two reordering .
For compilers :
- For the latter operation volatile When writing , No matter what the previous operation is , Can't reorder .
- The previous operation is volatile When reading , No matter what the latter operation is , Can't reorder .
- Previous operation volatile Write , The latter operation volatile read , Cannot reorder .
For processors :
When the compiler generates bytecode , A memory barrier is inserted in the instruction sequence to prevent a particular type of processor reordering .
Recommended reading :Java Theory and practice : Use... Correctly Volatile Variable
边栏推荐
猜你喜欢

English语法_不定代词 - other / another

06、类神经网络

filters获取data中的数据;filters使用data中的数据

Development of uni app offline ID card identification plug-in based on paddleocr

English grammar_ Indefinite pronoun - other / other

51单片机学习笔记(2)
![优质数对的数目[位运算特点+抽象能力考察+分组快速统计]](/img/c9/8f8f0934111f7ae8f8abd656d92f12.png)
优质数对的数目[位运算特点+抽象能力考察+分组快速统计]

Syntax summary of easygui

As methods for viewing and excluding dependencies

51单片机学习笔记(1)
随机推荐
39 simple version of millet sidebar exercise
[MySQL must know and know] trigger | permission management
51单片机学习笔记(1)
Browser based split screen reading
I hope some suggestions on SQL optimization can help you who are tortured by SQL like me
[C题目]力扣876. 链表的中间结点
The solution to the problem that the progress bar of ros2 installation connext RMW is stuck at 13%
The main function of component procurement system, digital procurement helps component enterprises develop rapidly
32 chrome调试工具的使用
Melodic + Realsense D435i 配置及错误问题解决
How to make a set of code fit all kinds of screens perfectly?
IP地址分类,判断一个网段是子网超网
AS查看依赖关系和排除依赖关系的办法
Awk from entry to earth (24) extract the IP of the instruction network card
Paddlenlp之UIE关系抽取模型【高管关系抽取为例】
PS making and loading GIF pictures tutorial
Dpkg package download addresses of various platforms (including arm64)
河源市区推出消防安全主题奶茶 助推夏季火灾防控
Alibaba cloud installs mysql5.7
Idea error failed to determine a suitable driver class