Rust Atomic总结笔记
Atomic operations are indivisable; they have either fully completed, or they haven’t happened yet.
陽了先記下來,后面再做視頻。原子(Automic)操作是不可再分的操作,要么全部執行完成,要么全部不執行。
Atomic operations in Rust are done through the atomic types in std::sync::atomic , such as AtomicI32 .
在Rust中原子操作通過std::sync::atomic模塊下的原子類型提供,比如:AtomicI32.
Not all atomic types are available on all platforms.
并不是所有的原子類型在所有平臺上都有提供
The relative ordering of atomic operations is tricky when multiple variables are involved.?
涉及多個變量時原子操作的相對順序是需要特別注意的地方。
Simple loads and stores are nice for very basic inter-thread communication, like stop flags and status reporting
簡單的存取(load和store)適用于比較簡單的線程內部通信,比如:停止標志,狀態報告。
Lazy initialization can be done as a race, without causing a data race.
懶初始化可以在竟態的環境中完成而不引起數據競爭。
Fetch-and-modify operations allow for a small set of basic atomic modifications that are especially useful when multiple threads are modifying the same atomic variable.
獲取后修改(Fetch-and-modify)操作在多個線程中修改同一個原子變量時比較有用。
Atomic addition and subtraction silently wrap around on overflow
需要注意原子類型做加減操作時如果發生了溢出,是不會報錯的。
Compare-and-exchange operations are the most flexible and general, and a building block for making any other atomic operation.
比較后交換(Compare-and-exchange)操作比較靈活通用,也是實現其它類型操作的基礎。
A weak compare-and-exchange operation can be slightly more efficient.
弱比較后交換(weak compare-and-exchange)操作可能更高效
總結
以上是生活随笔為你收集整理的Rust Atomic总结笔记的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 纯干货:微软漏洞中国第一人黄正——如何用
- 下一篇: 网格搜索算法与K折交叉验证