知识卡片

普通读书笔记卡 · 10294.a.3.c.1.b · 生成模型:未记录

CAS比较值与ABA

理解等级:中级

比较并交换只在当前值等于预期值时执行写入,可用于发布事先准备好的结果。若另一个线程将值从 A 改为 B 再改回 A,比较仍会成功。看到相同值只能证明比较时的状态相等,无法证明中间没有变化。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《Database Internals》Chapter 11. Replication and Consistency(book-source:extracted/Database Internals A deep-dive into how distributed data systems work (Alex Petrov)/_epub-src/OEBPS/ch11.html#idm46104530308008,段 108) - 结论依据:原文以 A→B→A 解释单纯比较当前值无法证明历史未变。 - 原始内容:Most of the programming languages these days offer atomic primitives that allow atomic write and compare-and-swap (CAS) operations. Atomic write operations do not consider current register values, unlike CAS, that move from one value to the next only when