Rust Atomic summary notes

Atomic operations are indivisable; they have either fully completed, or they haven’t happened yet.

Write it down first, and make a video later. Atomic (Automic) operations are indivisible operations, either all of them are executed, or none of them are executed.

Atomic operations in Rust are done through the atomic types in std::sync::atomic , such as AtomicI32 .

Atomic operations in Rust are provided by atomic types under the std::sync::atomic module, such as: AtomicI32.

Not all atomic types are available on all platforms.

Not all atom types are available on all platforms

The relative ordering of atomic operations is tricky when multiple variables are involved. 

The relative order of atomic operations when multiple variables are involved is where special attention is required.

Simple loads and stores are nice for very basic inter-thread communication, like stop flags and status reporting

Simple access (load and store) is suitable for relatively simple inter-thread communication, such as: stop sign, status report.

Lazy initialization can be done as a race, without causing a data race.

Lazy initialization can be done in race conditions without causing data races.

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 operations are useful when multiple threads modify the same atomic variable.

Atomic addition and subtraction silently wrap around on overflow

It should be noted that if an overflow occurs when the atomic type is added or subtracted, no error will be reported.

Compare-and-exchange operations are the most flexible and general, and a building block for making any other atomic operation.

The compare-and-exchange (Compare-and-exchange) operation is more flexible and general, and it is also the basis for implementing other types of operations.

A weak compare-and-exchange operation can be slightly more efficient.

Weak compare-and-exchange operations may be more efficient

おすすめ

転載: blog.csdn.net/tianlangstudio/article/details/128441791