@@ -2832,54 +2832,21 @@ exploiting.]
2832
2832
2833
2833
### Communication between tasks
2834
2834
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.
2883
2850
2884
2851
2885
2852
### Task lifecycle
0 commit comments