当前位置:网站首页>"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
边栏推荐
- Gonzalez Digital Image Processing Chapter 1 Introduction
- Wechat official account official environment online deployment, third-party public platform access
- MySQL 45 talks about | 06 global locks and table locks: Why are there so many obstacles to adding a field to a table?
- 44 新浪导航 ,小米边栏 练习
- 物理量与单位符号的书写标准
- The concept and operation rules of calculus of variations
- D2. picking carrots (hard version) (one question per day)
- SSH服务器拒绝了密码
- Gameframework making games (I)
- 国联证券买股票开户安全吗?
猜你喜欢

【MySQL必知必会】触发器 | 权限管理
![优质数对的数目[位运算特点+抽象能力考察+分组快速统计]](/img/c9/8f8f0934111f7ae8f8abd656d92f12.png)
优质数对的数目[位运算特点+抽象能力考察+分组快速统计]

苹果官网产品打折 买iPhone 13 Pro Max 可省600元

云安全技术发展综述

L1和L2正则化

45padding won't open the box

【口才】谈判说服技巧及策略

Wechat official account official environment online deployment, third-party public platform access

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

006操作符简介
随机推荐
Development of uni app offline ID card identification plug-in based on paddleocr
Sudo rosdep init error ROS installation problem solution
Kibana operation es
Ssh server rejected password
LeetCode-198-打家劫舍
Thymeleaf notes
Under the epidemic, the biomedical industry may usher in breakthrough development
39 simple version of millet sidebar exercise
LeetCode_因式分解_简单_263.丑数
32 chrome调试工具的使用
Deng Qinglin, a technical expert of Alibaba cloud: Best Practices for disaster recovery and remote multi activity across availability zones on cloud
各种平台dpkg包下载地址(包括arm64)
Spark 参数配置的几种方法
C language and SQL Server database technology
[MySQL must know and know] trigger | permission management
[C题目]力扣206. 反转链表
Overview of cloud security technology development
[MySQL series] - how much do you know about the index
43 box model
Gameframework making games (II) making UI interface