Deprecated communication between tasks
Communication between tasks is facilitated by ports (in the receiving task), and channels (in the sending task). Any number of channels may feed into a single port. Ports and channels may only transmit values of unique types; that is, values that are statically guaranteed to be accessed by a single 'owner' at a time. Unique types include scalars, vectors, strings, and records, tags, tuples and unique boxes (~T
) thereof. Most notably, shared boxes (@T
) may not be transmitted across channels.
let po = comm::Port();
let ch = comm::Chan(po);
do task::spawn {
comm::send(ch, "Hello, World");
}
io::println(comm::recv(p));
Use of this module is deprecated in favor of core::pipes
. In the core::comm
will likely be rewritten with pipes, at which point it will once again be the preferred module for intertask communication.
port_id
Chan
- A communication endpoint that can send messagesPort
- A communication endpoint that can receive messagesrust_port
PortPtr
for Port<T>
for Chan<T>
Chan
- Constructs a channelPort
- Constructs a portPortPtr
as_raw_port
- Internal function for converting from a channel to a portlisten
- Open a new receiving channel for the duration of a functionpeek
- Returns true if there are messages availablepeek_
peek_chan
recv
- Receive from a portrecv_
- Receive on a raw port pointerselect2
- Receive on one of two portssend
- Sends data over a channeloldcomm::rusti
oldcomm::rustrt
port_id
type port_id = int
Chan
A communication endpoint that can send messages
Each channel is bound to a port when the channel is constructed, so the destination port for a channel must exist before the channel itself. Channels are weak: a channel does not keep the port it is bound to alive. If a channel attempts to send data to a dead port that data will be silently dropped. Channels may be duplicated and themselves transmitted over other channels.
Chan_(port_id)
Port
A communication endpoint that can receive messages
Each port has a unique per-task identity and may not be replicated or transmitted. If a port value is copied, both copies refer to the same port. Ports may be associated with multiple chan
s.
Port_(@PortPtr<T>)
rust_port
PortPtr
struct PortPtr <T: Owned>{
po: *rust_port,
}
Port<T>
chan
fn chan() -> Chan<T>
send
fn send(v: T)
recv
fn recv() -> T
peek
fn peek() -> bool
Chan<T>
chan
fn chan() -> Chan<T>
send
fn send(v: T)
recv
fn recv() -> T
peek
fn peek() -> bool
Chan
fn Chan<T: Owned>(p: &Port<T>) -> Chan<T>
Constructs a channel. The channel is bound to the port used to construct it.
Port
fn Port<T: Owned>() -> Port<T>
Constructs a port
PortPtr
fn PortPtr<T: Owned>(po: *rust_port) -> PortPtr<T>
as_raw_port
fn as_raw_port<T: Owned, U>(ch: Chan<T>, f: &fn(*rust_port) -> U) -> U
Internal function for converting from a channel to a port
Fails if the port is detached or dead. Fails if the port is owned by a different task.
listen
fn listen<T: Owned, U>(f: &fn(Chan<T>) -> U) -> U
Open a new receiving channel for the duration of a function
peek
fn peek<T: Owned>(p: Port<T>) -> bool
Returns true if there are messages available
peek_
fn peek_(p: *rust_port) -> bool
peek_chan
fn peek_chan<T: Owned>(ch: Chan<T>) -> bool
recv
fn recv<T: Owned>(p: Port<T>) -> T
Receive from a port. If no data is available on the port then the task will block until data becomes available.
recv_
fn recv_<T: Owned>(p: *rust_port) -> T
Receive on a raw port pointer
select2
fn select2<A: Owned, B: Owned>(p_a: Port<A>, p_b: Port<B>) -> Either<A, B>
Receive on one of two ports
send
fn send<T: Owned>(ch: Chan<T>, data: T)
Sends data over a channel. The sent data is moved into the channel, whereupon the caller loses access to it.