当前位置:网站首页>[multithreading] non atomic agreement of long and double
[multithreading] non atomic agreement of long and double
2022-07-28 09:27:00 【Tanyue Jianzhi Dachang】
long and double The nonatomic agreement of
Java Memory model requirements lock、unlock、read、load、assign、use、store、write this 8 All operations are atomic , But for 64 Bit data type (double、long) Defines relatively loose regulations : Allowing virtual machines will not be volatile Embellished 64 The read-write operation of bit data is divided into two operations 32 Bit operation , That is, the virtual machine can be allowed without guarantee 64 Bit data type load、store、read and write Atomicity of operation .
Possible problems caused by non atomic agreements
If there are multiple threads sharing an undeclared volatile Of long or double Variable of type , And read and modify it at the same time , It is possible that a thread will read " Half a variable " Or half correct and half wrong failure data .
Solution in practical application
Because of the problems that may be caused by the above , It's bound to be right long and double Type variables should be operated with volatile keyword , In fact, it is as follows :
1、64 Bit java This problem does not exist in virtual machines , Can operate 64 A data
2、 Currently commercial JVM Basically, they will 64 The operation of bit data is implemented as an atomic operation
So we usually don't need to write code with long and double Variables are specifically declared as volatile
边栏推荐
- leetcode 452. Minimum Number of Arrows to Burst Balloons 用最少数量的箭引爆气球(中等)
- 【多线程】println方法底层原理
- QT基础练手小程序-简单计算器设计(附带源码,解析)
- 01 tensorflow calculation model (I) - calculation diagram
- 01-TensorFlow计算模型(一)——计算图
- Recommend an artifact to get rid of the entanglement of variable names and a method to modify file names in batches
- A perfect cross compilation environment records the shell scripts generated by PETA
- [high number] high number plane solid geometry
- MQTT. JS introductory tutorial: learning notes
- Conditions and procedures of stock index futures account opening
猜你喜欢
随机推荐
Openshift 4 - use verticalpodautoscaler to optimize application resource request and limit
ES6 变量的解构赋值
FPGA开发学习开源网站汇总
7 C控制语句:分支和跳转
51单片机存储篇:EEPROM(I2C)
【SwinTransformer源码阅读二】Window Attention和Shifted Window Attention部分
Common prototype methods of canvas and the application of drawing pictures
【多线程】println方法底层原理
1.5 merge\rebase\revert\stash\branch
The cooperation between starfish OS and metabell is just the beginning
MQTT.js 入门教程:学习笔记
使用 GBase C API 执行存储过程是怎样的?
RGB-T追踪——【多模态融合】Visible-Thermal UAV Tracking: A Large-Scale Benchmark and New Baseline
C#简单调用FMU ,进行仿真计算
网络层的IP协议
2022安全员-C证特种作业证考试题库及答案
[gossip] the development of programmers needs two abilities most
Promise学习笔记
如何在多线程环境下使用 GBase C API ?
【多线程】long和double的非原子性协定







![[swintransformer source code reading II] window attention and shifted window attention](/img/fb/5273d87fed66c75a92aec8e94980a3.png)

