当前位置:网站首页>[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;
}
}
}
边栏推荐
- [rust notes] 06 package and module
- Talking about: is the HashSet set ordered or disordered /hashset set unique, why can we store elements with the same content
- MySQL containerization (1) docker installation MySQL
- Delete the last character of the string in golang
- Kwai 20200412 recruitment
- 详解sizeof、strlen、指针和数组等组合题
- Un système de gestion de centre commercial pour la conception de cours de technologie d'application de base de données
- 使用base64编码传图片
- Unity learning notes
- Golang's range
猜你喜欢

Mall management system of database application technology course design

Unity learning notes
![[RPC] RPC remote procedure call](/img/dc/872204ea47fcff04cdb72e18a2a4ef.jpg)
[RPC] RPC remote procedure call

Explain sizeof, strlen, pointer, array and other combination questions in detail

Chocolate installation

详解sizeof、strlen、指针和数组等组合题

Use of ue5 QRcode plug-in

Base64和Base64URL
![[concurrent programming] consistency hash](/img/5e/3d0a52caa8ca489a6e6267274bbb39.jpg)
[concurrent programming] consistency hash

Unity editor expansion - controls, layouts
随机推荐
[concurrent programming] Table hopping and blocking queue
[rust notes] 11 practical features
Mysql容器化(1)Docker安装MySQL
producer consumer problem
Unity editor expansion - window, sub window, menu, right-click menu (context menu)
Unity notes 1
【云原生】微服务之Feign的介绍与使用
[cloud native] introduction and use of feign of microservices
Encoding and decoding of golang URL
Monotonic stack -503 Next bigger Element II
MySQL containerization (1) docker installation MySQL
Gradle's method of dynamically modifying APK package name
Map的实现类的顺序性
Graphics_ Learnopongl learning notes
Mxone Pro adaptive 2.0 film and television template watermelon video theme apple cmsv10 template
Advanced OSG collision detection
Swagger document configuration
[public key cryptography] ECC elliptic cryptosystem (implementing ElGamal encryption method)
Campus lost and found platform based on SSM, source code, database script, project import and operation video tutorial, Thesis Writing Tutorial
[concurrent programming] concurrent tool class of thread