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)操作可能更高效

猜你喜欢

转载自blog.csdn.net/tianlangstudio/article/details/128441791