当前位置:网站首页>[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;
}
}
}
边栏推荐
- Conversion between golang JSON format and structure
- [concurrent programming] Table hopping and blocking queue
- Jupyter remote server configuration and server startup
- Kwai 20200412 recruitment
- 分配异常的servlet
- Unity editor expansion - the framework and context of unity imgui
- Encoding and decoding of golang URL
- Redis的数据结构
- XPath实现XML文档的查询
- Cesium service deployment, and import and display local 3dfiles data
猜你喜欢

GIS实战应用案例100篇(七十八)-多规合一数据库设计及数据入库

Redis data structure

梯度下降法求解BP神经网络的简单Demo

php-fpm软件的安装+openresty高速缓存搭建

Advanced OSG collision detection
![[MySQL] MySQL Performance Optimization Practice: introduction of database lock and index search principle](/img/b7/7bf2a4a9ab51364352aa5e0a196b6d.jpg)
[MySQL] MySQL Performance Optimization Practice: introduction of database lock and index search principle

MXone Pro自适应2.0影视模板西瓜视频主题苹果cmsV10模板

Gradle's method of dynamically modifying APK package name

Simple demo of solving BP neural network by gradient descent method

C course design employee information management system
随机推荐
Huawei interview summary during the epidemic
Unity editor expansion - scrolling list
jupyter远程服务器配置以及服务器开机自启
P1596 [USACO10OCT]Lake Counting S
Collection interface
Swagger document configuration
【更新中】微信小程序学习笔记_3
Use of ue5 QRcode plug-in
Find the intersection of line segments
[concurrent programming] thread foundation and sharing between threads
Golang time format sorting
Kunlunbase meetup is waiting for you!
LinkList
php-fpm软件的安装+openresty高速缓存搭建
Development material set
Encoding and decoding of golang URL
796 · unlock
[rust notes] 05 error handling
Unity editor expansion - controls, layouts
【Rust 笔记】10-操作符重载