Enum std::sync::atomic::Ordering1.0.0[][src]

#[non_exhaustive]
pub enum Ordering {
    Relaxed,
    Release,
    Acquire,
    AcqRel,
    SeqCst,
}
Expand description

原子内存顺序

内存顺序指定原子操作同步内存的方式。 在最弱的 Ordering::Relaxed 中,仅同步操作直接触摸的内存。 另一方面,Ordering::SeqCst 操作的存储 - 加载对同步了其他内存,同时还保留了所有线程中此类操作的总顺序。

Rust 的内存顺序为 the same as those of C++20

有关更多信息,请参见 nomicon

Variants (Non-exhaustive)

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Relaxed

没有排序约束,只有原子操作。

对应于 C++ 20 中的 memory_order_relaxed

Release

当与存储耦合时,所有先前的操作都将在使用 Acquire (或更高级) 排序加载此值之前进行排序。

特别是,所有以前的写入操作对执行此值 Acquire (或更强) 的所有线程均可见。

请注意,对组合加载和存储的操作使用此顺序将导致 Relaxed 加载操作!

此排序仅适用于可以执行存储的操作。

对应于 C++ 20 中的 memory_order_release

Acquire

与加载耦合时,如果加载的值是由具有 Release (或更高级) 排序的存储操作写入的,则所有后续操作在该存储之后都将被排序。 特别是,所有后续加载将看到在存储之前写入的数据。

请注意,对组合加载和存储的操作使用此顺序将导致 Relaxed 存储操作!

此排序仅适用于可以执行加载的操作。

对应于 C++ 20 中的 memory_order_acquire

AcqRel

同时具有 AcquireRelease 的效果: 对于负载,它使用 Acquire 排序。对于商店,它使用 Release 排序。

请注意,在 compare_and_swap 的情况下,该操作可能最终不执行任何存储而因此仅具有 Acquire 排序。

但是,AcqRel 将永远不会执行 Relaxed 访问。

此排序仅适用于将加载和存储结合在一起的操作。

对应于 C++ 20 中的 memory_order_acq_rel

SeqCst

Acquire/Release/AcqRel (分别用于加载,存储和随存储加载操作) 一样,另外保证所有线程都可以按相同的顺序看到所有顺序一致的操作。

对应于 C++ 20 中的 memory_order_seq_cst

Trait Implementations

返回值的副本。 Read more

source 执行复制分配。 Read more

使用给定的格式化程序格式化该值。 Read more

将该值输入给定的 HasherRead more

将这种类型的切片送入给定的 Hasher 中。 Read more

此方法测试 selfother 值是否相等,并由 == 使用。 Read more

此方法测试 !=

Auto Trait Implementations

Blanket Implementations

获取 selfTypeIdRead more

从拥有的值中一成不变地借用。 Read more

从拥有的值中借用。 Read more

执行转换。

执行转换。

获得所有权后的结果类型。

通常通过克隆从借用数据中创建拥有的数据。 Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into #41263)

recently added

使用借来的数据来替换拥有的数据,通常是通过克隆。 Read more

发生转换错误时返回的类型。

执行转换。

发生转换错误时返回的类型。

执行转换。