@@ -1474,6 +1474,15 @@ Each channel is bound to a port when the channel is constructed, so the
1474
1474
destination port for a channel must exist before the channel itself. A channel
1475
1475
cannot be rebound to a different port from the one it was constructed with.
1476
1476
1477
+ Channels are weak: a channel does not keep the port it is bound to
1478
+ alive. Ports are owned by their allocating task and cannot be sent over
1479
+ channels; if a task dies its ports die with it, and all channels bound to
1480
+ those ports no longer function. Messages sent to a channel connected to a dead
1481
+ port will be dropped.
1482
+
1483
+ Channels are immutable types with meaning known to the runtime; channels can
1484
+ be sent over channels.
1485
+
1477
1486
Many channels can be bound to the same port, but each channel is bound to a
1478
1487
single port. In other words, channels and ports exist in an N:1 relationship,
1479
1488
N channels to 1 port. @footnote {It may help to remember nautical terminology
@@ -1482,20 +1491,14 @@ channels -- may lead to the same port.}
1482
1491
1483
1492
Each port and channel can carry only one type of message. The message type is
1484
1493
encoded as a parameter of the channel or port type. The message type of a
1485
- channel is equal to the message type of the port it is bound to.
1494
+ channel is equal to the message type of the port it is bound to. The types of
1495
+ messages must be of @emph {unique } kind.
1486
1496
1487
1497
Messages are generally sent asynchronously, with optional rate-limiting on the
1488
1498
transmit side. A channel contains a message queue and asynchronously sending a
1489
1499
message merely inserts it into the sending channel's queue; message receipt is
1490
1500
the responsibility of the receiving task.
1491
1501
1492
- Queued messages in channels are charged to the @emph {sending } task. If too
1493
- many messages are queued for transmission from a single sending task, without
1494
- being received by a receiving task, the sending task may exceed its memory
1495
- budget, which causes a run-time signal. To help control this possibility, a
1496
- semi-synchronous send operation is possible, which blocks until there is room
1497
- in the existing queue before sending send.
1498
-
1499
1502
Messages are sent on channels and received on ports using standard library
1500
1503
functions.
1501
1504
@@ -2166,9 +2169,6 @@ Rust; they cannot be used as user-defined identifiers in any context.
2166
2169
* Ref.Type.Tag :: Disjoint unions of heterogeneous types.
2167
2170
* Ref.Type.Fn :: Subroutine types.
2168
2171
* Ref.Type.Iter :: Scoped coroutine types.
2169
- * Ref.Type.Port :: Unique inter-task message-receipt endpoints.
2170
- * Ref.Type.Chan :: Copyable inter-task message-send capabilities.
2171
- * Ref.Type.Task :: General coroutine-instance types.
2172
2172
* Ref.Type.Obj :: Abstract types.
2173
2173
* Ref.Type.Constr :: Constrained types.
2174
2174
* Ref.Type.Type :: Types describing types.
@@ -2472,92 +2472,6 @@ for each (i: int in range(5,7)) @{
2472
2472
@}
2473
2473
@end example
2474
2474
2475
-
2476
- @node Ref.Type.Port
2477
- @subsection Ref.Type.Port
2478
- @cindex Port types
2479
- @cindex Communication
2480
-
2481
- The port type-constructor @code {port } forms types that describe ports. A port
2482
- is the @emph {receiving end } of a typed, asynchronous, simplex inter-task
2483
- communication facility. @xref {Ref.Task.Comm }. A @code {port } type takes a
2484
- single type parameter, denoting the type of value that can be received from a
2485
- @code {port } value of that type.
2486
-
2487
- Ports are modeled as stateful native types, with built-in meaning to the
2488
- language. They cannot be transmitted over channels or otherwise replicated,
2489
- and are always local to the task that creates them.
2490
-
2491
- Ports (like channels) can only be carry types of unique kind. No shared or
2492
- pinned values can pass over a port or channel.
2493
-
2494
- An example of a @code {port } type:
2495
- @example
2496
- type svp = port<[str]>;
2497
- let p: svp = get_port();
2498
- let v: [str] = p.recv();
2499
- @end example
2500
-
2501
- @node Ref.Type.Chan
2502
- @subsection Ref.Type.Chan
2503
- @cindex Channel types
2504
- @cindex Communication
2505
-
2506
- The channel type-constructor @code {chan } forms types that describe channels. A
2507
- channel is the @emph {sending end } of a typed, asynchronous, simplex inter-task
2508
- communication facility. @xref {Ref.Task.Comm }. A @code {chan } type takes a
2509
- single type parameter, denoting the type of value that can be sent to a
2510
- channel of that type.
2511
-
2512
- Channels are immutable, and can be transmitted over channels to other
2513
- tasks. They are modeled as immutable native types with built-in meaning to the
2514
- language.
2515
-
2516
- Channels (like ports) can only be carry types of unique kind. No
2517
- pinned or shared values can pass over a port or channel.
2518
-
2519
- When a task sends a message into a channel, the task forms an outgoing queue
2520
- associated with that channel. The per-task queue @emph {associated } with a
2521
- channel can be indirectly manipulated by the task, but is @emph {not } otherwise
2522
- considered ``part of'' to the channel: the queue is ``part of'' the
2523
- @emph {sending task }. Sending a channel to another task does not copy the queue
2524
- associated with the channel.
2525
-
2526
- Channels are also @emph {weak }: a channel is directly coupled to a particular
2527
- destination port on a particular task, but does not keep that port or task
2528
- @emph {alive }. A channel may therefore fail to operate at any moment. If a task
2529
- sends a message to a channel that is connected to a nonexistent port, the
2530
- message is dropped.
2531
-
2532
- An example of a @code {chan } type:
2533
- @example
2534
- type svc = chan<[str]>;
2535
- let c: svc = get_chan();
2536
- let v: [str] = ["hello", "world"];
2537
- std::comm::send(c, v);
2538
- @end example
2539
-
2540
- @node Ref.Type.Task
2541
- @subsection Ref.Type.Task
2542
- @cindex Task type
2543
-
2544
- The task type @code {task } describes values that are @emph {live
2545
- tasks }.
2546
-
2547
- Tasks form an @emph {ownership tree } in which each task (except the root task)
2548
- is directly owned by exactly one parent task. The purpose of a variable of
2549
- @code {task } type is to manage the lifecycle of the associated
2550
- task. Communication is carried out solely using channels and ports.
2551
-
2552
- Like ports, tasks are modeled as mutable native types with built-in meaning to
2553
- the language. They cannot be transmitted over channels or otherwise
2554
- replicated, and are always local to the task that spawns them.
2555
-
2556
- If all references to a task are dropped (due to the release of any structure
2557
- holding those references), the runtime signals the un-referenced task, which
2558
- then fails. @xref {Ref.Task.Life }.
2559
-
2560
-
2561
2475
@node Ref.Type.Obj
2562
2476
@subsection Ref.Type.Obj
2563
2477
@c * Ref.Type.Obj:: Object types.
0 commit comments