当前位置:网站首页>[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;
}
}
}
边栏推荐
- Creation of osgearth earth files to the earth ------ osgearth rendering engine series (1)
- 如何应对数仓资源不足导致的核心任务延迟
- Cloudcompare learning (1) - cloudcompare compilation and common plug-in implementation
- Osgearth north arrow display
- 单调栈-84. 柱状图中最大的矩形
- How does unity fixedupdate call at a fixed frame rate
- [rust notes] 11 practical features
- Unity notes 1
- Unity Editor Extension - drag and drop
- Intersectionpicker in osgearth
猜你喜欢
Thymeleaf 404 reports an error: there was unexpected error (type=not found, status=404)
【更新中】微信小程序学习笔记_3
Mall management system of database application technology course design
matlab神经网络所有传递函数(激活函数)公式详解
Graphics_ Learnopongl learning notes
详解sizeof、strlen、指针和数组等组合题
注解简化配置与启动时加载
Introduction to hexadecimal coding
Graphics_ Games101/202 learning notes
Unity editor expansion - scrolling list
随机推荐
Why can void * be a general pointer
Simply start with the essence and principle of SOM neural network
【Rust 笔记】11-实用特型
Transmit pictures with Base64 encoding
MySQL containerization (1) docker installation MySQL
[K & R] Chinese Second Edition personal questions Chapter1
796 · unlock
Detailed explanation of all transfer function (activation function) formulas of MATLAB neural network
[rust notes] 02 ownership
Golang's range
【Rust 笔记】07-结构体
Introduction to Base64 coding
【Rust笔记】06-包和模块
使用base64编码传图片
Message pack in C deserializes array objects
Cesium service deployment, and import and display local 3dfiles data
Unity4.3.1 engine source code compilation process
Development experience and experience
Markdown directory generation
Osganimation library parsing