Skip to content

[guide] A new guide that centers around Send and Sync should be written #18938

Closed
@Kimundi

Description

@Kimundi

Currently, the only Rust guide that talks about concurrency is the task guide, which talks about spawn, channels, Futures and Arcs and how to use them.

However, Rusts concurrency story is not based on those library types, its based on its ownership and borrowing semantic and the two build-in traits Send and Sync.

A rewritten concurrency guide could start by talking around the two core problems with concurrent/parallel code:

  1. Making sure that objects created on one thread can be safely moved into another thread and then used there. (Examples: global allocator vs thread-local allocator, FFI bindings that need to stay on one thread)
  2. Making sure that objects can be safely accessed from different threads in parallel. (Examples: worker threads with shared memory, global variables)

And then talk about how those two cases are, per definition, covered with the two build-in traits:

  1. Send expresses whether a type can be safely ownership-transferred across thread boundaries
  2. Sync expresses whether a type can be safely accessed through shared references from different threads.

After each of these those two traits got explained, the guide could go into details about language semantics and std library APIs that make use of them, eg task spawning works with Send, Arcs are Send and require Sync on the inner type, while channels are sendable endpoints that can only transfer sendable types, static variables that contain Sync types are safe to access, etc.

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