Crust of Rust: Channels
In this (fifth) Crust of Rust video, we cover multi-produce/single-consumer (mpsc) channels, by re-implementing some of the std::sync::mpsc types from the standard library. As part of that, we cover what channels are used for, how they work at a high level, different common channel variants, and common channel implementations. In the process, we go over some common Rust concurrency primitives like Mutex and Condvar.
This is a rich topic, and I highly recommend you go and try to read the crossbeam-channel or flume source code if you're hungry for more! Please also leave questions here or on Discord if you're confused, and I'll try to help explain what's going on.
You can find the final code at https://gist.github.com/jonhoo/935060885d0d832d463fda3c89e8259d and the Discord at https://discord.gg/RJdqQ9n
0:00:00 Introduction
0:08:20 Initial structure
0:14:27 Structure Q&A
0:19:20 send and recv
0:29:03 send/recv Q&A
0:34:36 Does it work?
0:40:28 Zero senders
0:46:27 Q&A
0:50:53 Why does it hang?
0:53:08 Implementation Q&A
0:58:37 Synchronous channels
1:05:55 Batch recv optimization
1:13:23 Channel flavors
1:18:48 Flavor Q&A
1:22:32 Other implementations
1:32:24 Future-aware channels
1:36:27 Where next?
1:38:24 Channels Q&A
You can find crossbeam-channel at https://github.com/crossbeam-rs/crossbeam/tree/master/crossbeam-channel, and flume at https://github.com/zesterer/flume/.
You can watch the live version with comments at https://www.youtube.com/watch?v=JvBUKsFIUKw
Other Videos By Jon Gjengset
2021-04-02 | Crust of Rust: Atomics and Memory Ordering |
2021-03-13 | Crust of Rust: The Drop Check |
2021-02-20 | Crust of Rust: Subtyping and Variance |
2021-01-23 | Q&A January 2021 (now with cat) |
2020-12-12 | The Unsafe Chronicles: Exhibit A: Aliasing Boxes |
2020-11-21 | A Cool Generic Concurrency Primitive in Rust |
2020-11-14 | Crust of Rust: Sorting Algorithms |
2020-10-23 | Thesis: Partial State in Dataflow-Based Materialized Views |
2020-08-19 | Q&A August #2 2020 |
2020-08-09 | Q&A August 2020 |
2020-08-05 | Crust of Rust: Channels |
2020-07-25 | Thesis Talk: The Evaluation Chapter |
2020-06-17 | Crust of Rust: Smart Pointers and Interior Mutability |
2020-05-27 | Crust of Rust: Iterators |
2020-04-29 | Crust of Rust: Declarative Macros |
2020-04-01 | (Partially) fixing a bug in a Rust research database |
2020-03-06 | Considering Rust |
2020-01-19 | Porting Java's ConcurrentHashMap to Rust (part 3) |
2019-12-14 | Porting Java's ConcurrentHashMap to Rust (part 2) |
2019-11-17 | Why are my videos so damn long‽ |
2019-11-17 | Porting Java's ConcurrentHashMap to Rust (part 1) |