Skip to content

Commit b2b32b7

Browse files
committed
---
yaml --- r: 24461 b: refs/heads/master c: 6c2c694 h: refs/heads/master i: 24459: 54f31c2 v: v3
1 parent 5b8a985 commit b2b32b7

File tree

2 files changed

+16
-49
lines changed

2 files changed

+16
-49
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 46371e107634ba9e8947cc1c45cecd8b24328e88
2+
refs/heads/master: 6c2c6947256db3841ceb3253ebace259a72dd917
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/doc/rust.md

Lines changed: 15 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2832,54 +2832,21 @@ exploiting.]
28322832

28332833
### Communication between tasks
28342834

2835-
With the exception of *unsafe* blocks, Rust tasks are isolated from
2836-
interfering with one another's memory directly. Instead of manipulating shared
2837-
storage, Rust tasks communicate with one another using a typed, asynchronous,
2838-
simplex message-passing system.
2839-
2840-
A _port_ is a communication endpoint that can *receive* messages. Ports
2841-
receive messages from channels.
2842-
2843-
A _channel_ is a communication endpoint that can *send* messages. Channels
2844-
send messages to ports.
2845-
2846-
Each port is implicitly boxed and mutable; as such a port has a unique
2847-
per-task identity and cannot be replicated or transmitted. If a port value is
2848-
copied, both copies refer to the *same* port. New ports can be
2849-
constructed dynamically and stored in data structures.
2850-
2851-
Each channel is bound to a port when the channel is constructed, so the
2852-
destination port for a channel must exist before the channel itself. A channel
2853-
cannot be rebound to a different port from the one it was constructed with.
2854-
2855-
Channels are weak: a channel does not keep the port it is bound to
2856-
alive. Ports are owned by their allocating task and cannot be sent over
2857-
channels; if a task dies its ports die with it, and all channels bound to
2858-
those ports no longer function. Messages sent to a channel connected to a dead
2859-
port will be dropped.
2860-
2861-
Channels are immutable types with meaning known to the runtime; channels can
2862-
be sent over channels.
2863-
2864-
Many channels can be bound to the same port, but each channel is bound to a
2865-
single port. In other words, channels and ports exist in an N:1 relationship,
2866-
N channels to 1 port. ^[It may help to remember nautical terminology
2867-
when differentiating channels from ports. Many different waterways --
2868-
channels -- may lead to the same port.]
2869-
2870-
Each port and channel can carry only one type of message. The message type is
2871-
encoded as a parameter of the channel or port type. The message type of a
2872-
channel is equal to the message type of the port it is bound to. The types of
2873-
messages must satisfy the `send` built-in trait.
2874-
2875-
Messages are generally sent asynchronously, with optional
2876-
rate-limiting on the transmit side. Each port contains a message
2877-
queue and sending a message over a channel merely means inserting it
2878-
into the associated port's queue; message receipt is the
2879-
responsibility of the receiving task.
2880-
2881-
Messages are sent on channels and received on ports using standard library
2882-
functions.
2835+
Rust tasks are isolated and generally unable to interfere with one another's memory directly,
2836+
except through [`unsafe` code](#unsafe-code).
2837+
All contact between tasks is mediated by safe forms of ownership transfer,
2838+
and data races on memory are prohibited by the type system.
2839+
2840+
Inter-task communication and co-ordination facilities are provided in the standard library.
2841+
These include:
2842+
- synchronous and asynchronous communication channels with various communication topologies
2843+
- read-only and read-write shared variables with various safe mutual exclusion patterns
2844+
- simple locks and semaphores
2845+
2846+
When such facilities carry values, the values are restricted to the [`Send` type-kind](#type-kinds).
2847+
Restricting communication interfaces to this kind ensures that no borrowed or managed pointers move between tasks.
2848+
Thus access to an entire data structure can be mediated through its owning "root" value;
2849+
no further locking or copying is required to avoid data races within the substructure of such a value.
28832850

28842851

28852852
### Task lifecycle

0 commit comments

Comments
 (0)