当前位置:网站首页>"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
边栏推荐
- 微信公众号正式环境上线部署,第三方公众平台接入
- 关于RDBMS和非RDBMS【数据库系统】
- Software testing -- 1. Outline of software testing knowledge
- Leetcode-198- house raiding
- QObject源码剖析-d指针和q指针
- Is it safe for Guolian securities to buy shares and open an account?
- Live classroom system 05 background management system
- BigDecimal rounds the data
- SQL优化的一些建议,希望可以帮到和我一样被SQL折磨的你
- Sudo rosdep init error ROS installation problem solution
猜你喜欢

006 operator introduction

SSM framework integration, simple case

51 single chip microcomputer learning notes (2)

关于ROS2安装connext RMW的进度条卡在13%问题的解决办法

基于AMD EPYC服务器的EDA芯片设计解决方案

Melody + realsense d435i configuration and error resolution

河源市区推出消防安全主题奶茶 助推夏季火灾防控

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

Resource not found: rgbd_launch 解决方案

Gameframework making games (I)
随机推荐
各种平台dpkg包下载地址(包括arm64)
32 use of chrome debugging tools
SSM framework integration, simple case
Realsense ROS installation configuration introduction and problem solving
jqgrid全选取消单行点击取消事件
D2. picking carrots (hard version) (one question per day)
软件测试 -- 1 软件测试知识大纲梳理
I hope some suggestions on SQL optimization can help you who are tortured by SQL like me
基于浏览器的分屏阅读
Spark 参数配置的几种方法
L1 and L2 regularization
[nuxt 3] (XI) transmission & module
C language and SQL Server database technology
Development of uni app offline ID card identification plug-in based on paddleocr
06、类神经网络
Writing standard of physical quantities and unit symbols
[C题目]力扣88. 合并两个有序数组
Pytorch training code writing skills, dataloader, Einstein logo
Polymorphism and interface
How to use the random number function of JMeter