hybridtheorylink / hybridtheorylink.github.io2

0 stars 0 forks source link

非阻塞同步算法与CAS(Compare and Swap)无锁算法 | HybridTheory #1

Open hybridtheorylink opened 5 years ago

hybridtheorylink commented 5 years ago

https://hybridtheorylink.github.io/2019/04/22/%E9%9D%9E%E9%98%BB%E5%A1%9E%E5%90%8C%E6%AD%A5%E7%AE%97%E6%B3%95%E4%B8%8ECAS-Compare-and-Swap-%E6%97%A0%E9%94%81%E7%AE%97%E6%B3%95/

锁(lock)的代价锁是用来做并发最简单的方式,当然其代价也是最高的。内核态的锁的时候需要操作系统进行一次上下文切换,加锁、释放锁会导致比较多的上下文切换和调度延时,等待锁的线程会被挂起直至锁释放。在上下文切换的时候,cpu之前缓存的指令和数据都将失效,对性能有很大的损失。操作系统对多线程的锁进行判断就像两姐妹在为一个玩具在争吵,然后操作系统就是能决定他们谁能拿到玩具的父母,这是很慢的。用户态的锁

hybridtheorylink commented 5 years ago

hello

hybridtheorylink commented 5 years ago

this is my first commit