Communication between threads can be implemented in a safe way by the use of channels. Rust's standard library has two kinds of channels defined in std::sync::mpsc:
- channel: This is an asynchronous, infinite buffer
- sync_channel: This is a synchronous, bounded buffer
The acronym mpsc refers to multi producer, single consumer. That is, these channels may have multiple writers but only a single reader. Both of these functions return a pair of generic values: a sender and a receiver. The sender can be used to push new things into the channel, while receivers can be used to get things from the channel. The sender implements the Clone trait while the receiver does not. This, paired with Rust's regular ownership system, allows the compiler ...