当前位置:网站首页>"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
边栏推荐
- Spark 参数配置的几种方法
- SQL优化的一些建议,希望可以帮到和我一样被SQL折磨的你
- BIO、NIO、AIO示例
- Number of high-quality number pairs [bit operation characteristics + abstract ability evaluation + grouping fast statistics]
- C language and SQL Server database technology
- 软件测试 -- 1 软件测试知识大纲梳理
- 37 元素模式(行内元素,块元素,行内块元素)
- MySQL的登陆【数据库系统】
- 基于AMD EPYC服务器的EDA芯片设计解决方案
- Polymorphism and interface
猜你喜欢

Browser based split screen reading

Resource not found: rgbd_launch 解决方案

SSM framework integration, simple case

27 选择器的分类

I2C设备驱动程序的层次结构

06. Neural network like

32 chrome调试工具的使用

Live classroom system 05 background management system

45padding won't open the box

Wechat official account official environment online deployment, third-party public platform access
随机推荐
06. Neural network like
Overview of cloud security technology development
Vs2017 large factory ERP management system source code factory general ERP source code
Awk from getting started to digging in (21) awk script debugging
Paddlenlp's UIE relationship extraction model [executive relationship extraction as an example]
Under the epidemic, the biomedical industry may usher in breakthrough development
awk从入门到入土(23)awk内置变量ARGC、ARGC--命令行参数传递
BigDecimal rounds the data
Products on Apple's official website can save 600 yuan by buying iPhone 13 Pro max at a discount
32 chrome调试工具的使用
Ten common application scenarios of redis
D2. Chopping Carrots (Hard Version) (每日一题)
easygui使用的语法总结
Writing standard of physical quantities and unit symbols
Paddlenlp之UIE关系抽取模型【高管关系抽取为例】
各种平台dpkg包下载地址(包括arm64)
苹果官网产品打折 买iPhone 13 Pro Max 可省600元
41 图片背景综合-五彩导航图
27 选择器的分类
SSM framework integration, simple case