简体   繁体   English

“别名”对于“同步”特征意味着什么?

[英]What does “alias” mean with respect to the `Sync` trait?

I'm learning Rust, trying to figure out the std::marker::Sync trait. 我正在学习Rust,试图找出std::marker::Sync特征。 The documentation for Sync starts with the following (version 1.1), emphasis mine: Sync的文档从以下(版本1.1)开始,强调我的:

Types that can be safely shared between threads when aliased . 别名时可以在线程之间安全共享的类型。

The precise definition is: a type T is Sync if &T is thread-safe. 精确的定义是:如果&T是线程安全的,则类型TSync In other words, there is no possibility of data races when passing &T references between threads. 换句话说,在线程之间传递&T引用时不存在数据争用的可能性。

As one would expect, primitive types like u8 and f64 are all Sync , and so are simple aggregate types containing them (like tuples, structs and enums). 正如人们所料,像u8f64这样的原始类型都是Sync ,包含它们的简单聚合类型(如元组,结构和枚举)也是如此。 ...

This makes zero sense to me, starting with the first sentence. 从第一句话开始,这对我来说毫无意义。 I thought aliasing has to do with statements such as: 我认为别名与以下语句有关:

type Name = String;

What does this have to do with synchronization? 这与同步有什么关系? Perhaps the term “alias” is overloaded here, and I'm missing the second meaning, but I can't find anywhere in the documentation referring to a second kind of aliasing. 也许术语“别名”在这里重载,我错过了第二个含义,但我在文档中的任何地方都找不到第二种别名。

Can someone point me in the right direction? 有人能指出我正确的方向吗?

A value is said to be aliased if there is more than one alias to it. 值是表示,如果有多个别名,以它的别名 An alias is just a name. 别名只是一个名字。

In this code: 在这段代码中:

let s1: String = "hello".into();
let s2: &String = &s1;

s1 and s2 are aliases of the same String value; s1s2是相同String值的别名; therefore, the String is aliased. 因此, String是别名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM