You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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)
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:
Send expresses whether a type can be safely ownership-transferred across thread boundaries
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.
The text was updated successfully, but these errors were encountered:
I opened both issues at the same time. #18936 is specifically about the current task/multithreading guide, while this is about a possible new rewrite of such a guide.
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
andSync
.A rewritten concurrency guide could start by talking around the two core problems with concurrent/parallel code:
And then talk about how those two cases are, per definition, covered with the two build-in traits:
Send
expresses whether a type can be safely ownership-transferred across thread boundariesSync
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
,Arc
s areSend
and requireSync
on the inner type, while channels are sendable endpoints that can only transfer sendable types,static
variables that containSync
types are safe to access, etc.The text was updated successfully, but these errors were encountered: