当前位置:网站首页>[concurrent programming 045] what is pseudo shared memory sequence conflict? How to avoid?
[concurrent programming 045] what is pseudo shared memory sequence conflict? How to avoid?
2022-04-22 04:27:00 【Tanyue sword finger factory】
What is pseudo shared memory order conflict ? How to avoid ?
Due to storage in CPU The cache line is a block of memory, not a single variable , Therefore, it is possible to store multiple variables in Same cache line in , When multiple threads modify When there are multiple variables in this cache line , Since only one thread can operate on the cache line at the same time , At this time, two threads modify two different variables under the same cache line at the same time , This is pseudo sharing , Also known as memory order conflict .
When pseudo sharing occurs , CPU You have to clear the assembly line , Can cause CPU It's a big expense .
How to avoid :
JDK1.8 Previously, this problem was generally avoided by byte filling , That is, when creating a variable, make
Fill the cache line where the variable is located with the fill field , This avoids storing multiple variables in the same cache line , For example, the following code :
If the cache behavior 64 byte , So we're in FilledLong Class padding 了 6 individual long A change of type
One long Type variables occupy 8 byte , Add your own value Variables occupy 8 Bytes , in total 56 byte . in addition , here FilledLong Is a class object , The object header of the bytecode of the class object occupies 8 byte , So a FilledLong The object actually takes up 64 Bytes of memory , This happens to fit into the same cache line .
JDK Provides sun.misc Contended annotation , To solve the pseudo sharing problem . Modify the above code as follows .

Particular attention
By default , @Contended Annotations are only used for Java Core class , such as rt Class under package .
If the class under the user's class path needs to use this annotation , Need to add JVM Parameters : - XX:-RestrictContended . The width of the fill is... By default 128, To customize the fill width, you can use the parameter -XX:ContendedPaddingWidth Parameters Set it up .
版权声明
本文为[Tanyue sword finger factory]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210954016850.html
边栏推荐
- L'échange et le partage des données sont au cœur de l'amélioration de l'efficacité de l'utilisation des données dans l'industrie des transports.
- H7-TOOL发布固件V2.15, 脱机烧录增加瑞萨,合泰以及IS25WP全系列SPI FLASH等(2022-04-14)
- Websocket learning
- Binary search for qualified values and local minimum values
- Filebeat collects log data and transfers it to redis. Different es indexes are created according to log fields through logstash
- Spark installation and use of educoder
- [machine learning] long and short term memory network (LSTM)
- 毕设-SSM校园二手书籍销售系统+论文
- 使用 nohup 命令将程序挂载在后台执行
- 04-Functions
猜你喜欢

Will the expired data of redis be deleted immediately?

Chapter 8 of C language programming (fifth edition of Tan Haoqiang) is good at using pointer exercises to analyze and answer

Sumo circle driving

pytorch使用profiler对模型性能分析时报错

Zuo Chengyun - Dachang question brushing class - the minimum number of exchanges of one character on the left and another character on the right

Intelligent power safety management system

Objectmapper, stop being new like a second product

Your mind will change your behavior, and your behavior will change your situation

How do I test the shuttle application? Unit test

Zuo Chengyun - Dachang brushing class - the point with the most rope coverage
随机推荐
Zuo Chengyun - Dachang question brushing class - the minimum number of exchanges of one character on the left and another character on the right
C entry - check the ID number with regular expressions.
【机器学习】长短时记忆网络(LSTM)
Sumo circle driving
ES6 practical tips
01-Read&Write
LeetCode 63. 不同路径 II
L1-046 divide singles (20 points)
04-Functions
Rsync remote synchronization
Knowledge points related to compliance type
rsync远程同步
iptables使用
01背包问题(二维数组解法以及一位数组优化)
WinPcap get device list
L1-048 matrix a multiplied by B (15 points)
How to solve the problem that the table association is not displayed when importing SQL from powerdesipowerdesigner
Insert a number into the ordered array (Bubble + rand function)
L3-022 subway one day tour (30 points) [Floyd + DFS]
Bi set - SSM campus second-hand book sales system + thesis