Skip to content

Ambiguous explanation of Sync in the book #28458

Closed
@critiqjo

Description

@critiqjo

When a type T implements Sync, 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 implements Sync, 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions