知识卡片
CAS校验更新前提
比较交换以一个原子操作验证旧值并在匹配时写入新值。若失败,调用者可用返回的实际值重新判断。它能保护单变量条件更新,多个变量间的约束要另行协调。反复冲突时也要考虑有界重试或退避。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Chapter 6. Reactive Programming 快照、决策与原子更新 · 查看原书依据
This is where we can appreciate why atomics are called atomics because their transactions are atomic. This means that no other transaction will happen on the atomic value while a transaction is being performed on the value. In the compare_exchange function, we are asserting that the atomic value is a certain value before we update it to the new value. If the value is not
参考来源
- 位置:《Async Rust Unleashing the Power of Fearless Concurrency (Maxwell Flitton, Caroline Morton)》第06章《Chapter 6. Reactive Programming》,快照、决策与原子更新(来源项目 book-source,extracted/Async Rust Unleashing the Power of Fearless Concurrency (Maxwell Flitton, Caroline Morton)/_epub-src/OEBPS/ch06.html#id41)
- 结论依据:compare_exchange 示例在实际值与预期不同时返回当前值,观察者可据此重算。
- 原始内容:This is where we can appreciate why atomics are called atomics because their transactions are atomic. This means that no other transaction will happen on the atomic value while a transaction is being performed on the value. In the compare_exchange function, we are asserting that the atomic value is a certain value before we update it to the new value. If the value is not