Channels between threads

There is an extra way of sending information between two or more threads. They are called channels, or more specifically, multi-producer, single-consumer FIFO communication primitives.

Let's first analyze what that means. Since they are multi-producer channels, you can send the data to the receiver from multiple threads at the same time. In the same way, since they are single-consumers, only one receiver will receive data from all the associated senders in the channel. Finally, FIFO comes from first input, first output, which means that the messages in the channel will be ordered by their creation timestamp, and you will only be able to read the second message after reading the first one in the receiver.

These channels ...

Get Rust High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.