当前位置:网站首页>[concurrent programming] atomic operation CAS
[concurrent programming] atomic operation CAS
2022-07-03 08:37:00 【keeper42】
syn Blocking based lock mechanism ,1、 Blocked threads have a high priority ,2、 What if the thread that gets the lock does not release the lock ?3、 A lot of competition , Consume cpu, At the same time, it brings deadlock or other security .
Atomic manipulation : Indivisible operation
CAS(compare and swap, Optimism lock , Lock free programming )
CAS Principle
CAS(Compare And Swap), The instruction level guarantees that this is an atomic operation
Three operators : A memory address V, A desired value A, A new value B
The basic idea : If the address V Top value and expected value A equal , Just give the address V new value B, If not , Do nothing .
loop ( Dead cycle , The spin ) It's going on in the CAS operation
CAS The problem of
ABA problem :A---》B----》A, resolvent : Introduce version number
The cost problem :CAS The operation has been unsuccessful for a long time ,cpu It's a constant cycle
compareAndSet
public void increament() {
while (true){
int i = atomicI.get();
boolean suc = atomicI.compareAndSet(i, ++i);
if (suc) {
break;
}
}
}
边栏推荐
- php-fpm软件的安装+openresty高速缓存搭建
- Transmit pictures with Base64 encoding
- [cloud native] introduction and use of feign of microservices
- Unity4.3.1 engine source code compilation process
- Unity editor expansion - window, sub window, menu, right-click menu (context menu)
- Unity learning notes
- 【Rust 笔记】13-迭代器(上)
- 十六进制编码简介
- 使用base64编码传图片
- MySQL containerization (1) docker installation MySQL
猜你喜欢
![[concurrent programming] thread foundation and sharing between threads](/img/26/60fbfe65b186867a3b1cb58d481226.jpg)
[concurrent programming] thread foundation and sharing between threads

Introduction to hexadecimal coding

Base64 and base64url

Servlet的生命周期

MySQL 8

Unity interactive water ripple post-treatment

Introduction to Base64 coding

单调栈-42. 接雨水

Mall management system of database application technology course design

【更新中】微信小程序学习笔记_3
随机推荐
UE4 source code reading_ Bone model and animation system_ Animation process
GIS实战应用案例100篇(七十八)-多规合一数据库设计及数据入库
Eating fruit
Golang string segmentation, substitution and interception
Unity Editor Extension - drag and drop
Ue5 opencv plug-in use
Swagger document configuration
Unity editor expansion - the design idea of imgui
Creation of osgearth earth files to the earth ------ osgearth rendering engine series (1)
Downward compatibility and upward compatibility
Pit & ADB wireless debugging of vivo real machine debugging
[concurrent programming] consistency hash
[concurrent programming] working mechanism and type of thread pool
Kunlunbase meetup is waiting for you!
Notes on understanding applets 2022/7/3
Cesium service deployment, and import and display local 3dfiles data
Creation and content of mapnode -- osgearth rendering engine series (2)
UE4 plug in development
Osgearth target selection
Unity editor expansion - window, sub window, menu, right-click menu (context menu)