-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Description
When a type
TimplementsSync, it indicates to the compiler that something of this type has no possibility of introducing memory unsafety when used from multiple threads concurrently.
The term "used" should be elaborated: "when used by immutable reference from ..."
It will not occur to a reader that a primitive type implements Sync.
For example, sharing immutable data with an atomic reference count is threadsafe. Rust provides a type like this,
Arc<T>, and it implementsSync, so it is safe to share between threads.
This might leave an impression that usize does not implement Sync but when wrapped with Arc, Arc<usize> will have Sync!! (This really was my impression until recently!).
Besides, saying Arc<T> implements Sync itself is incorrect -- it should say "Arc<T> implements Sync if and only if T implements Sync", or better, don't mention Arc at all...
Please word this section more carefully, so that confusion is eliminated in future...
Ref: section 4.6