Reputation: 3644
I'm learning Rust, trying to figure out the std::marker::Sync
trait. The documentation for Sync
starts with the following (version 1.1), emphasis mine:
Types that can be safely shared between threads when aliased.
The precise definition is: a type
T
isSync
if&T
is thread-safe. In other words, there is no possibility of data races when passing&T
references between threads.As one would expect, primitive types like
u8
andf64
are allSync
, and so are simple aggregate types containing them (like tuples, structs and enums). …
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?
Upvotes: 4
Views: 197
Reputation: 65732
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; therefore, the String
is aliased.
Upvotes: 4