Python 中 有 CAS 的实现吗
source link: https://www.v2ex.com/t/808500
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Google 了一下 "Python" "CAS",只是搜到了一些关于 GIL 的 ATOMIC 操作。
但是觉得 Python 的 Lock() 又有点沉,有大佬知道有没有类似 CAS 的轻量级实现吗?
Goat121 18 小时 50 分钟前
cas 和 java 又有什么关系了?人家实现 cas 的时候还没现代操作系统呢,你家 jvm 都没地方跑谢谢。
dqzcwxb 17 小时 59 分钟前
我没说 cas 跟 java 有关系,只是某些喷 java 的喜欢带上
同理设计模式也跟 java 没啥关系,还不是天天喷 java 设计模式滥用?
还羞与为伍,笑死
abersheeran 15 小时 33 分钟前 1
如果直接用 a = b,那你压根拿不到 a 的结果,因为 Python 没有指针,函数里赋值过去就没了。
如果用 nonlocal global 去修复拿结果的问题,那就没办法做到无副作用,而且这只是换了个 name,对象所在的内存还是没有变化。
综上所述,建议直接 threading.Lock,不会有人上了 Python 还扣这个锁的性能吧?大可不必啊
abersheeran 15 小时 31 分钟前
sujin190 15 小时 22 分钟前 1
sujin190 15 小时 19 分钟前
sujin190 15 小时 14 分钟前
2i2Re2PLMaDnghL 8 小时 34 分钟前
你这就好比大多数语言给 a=1 取个名字叫「赋值」,然后说『( Haskell 的) let a=1 in ... 有赋值的影子』,这说明你被词汇和词义限制住了思想。
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK