Skip to content
0:00 / 0:00

#mpsc#channels#mutex

Crust of Rust: Channels

Jon Gjengset

111K subscribers • 38 videos on Hallway

YouTube

Intermediate. Assumes working knowledge.

99K views6 years ago2 recommendations

Programming languagesSystems programmingRustConcurrency and parallelism

Jon Gjengset implements a multi-producer, single-consumer channel in Rust to explain concurrency primitives like Mutex and Condvar.

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 gist.github.com/jonhoo/935060885d0d832d463fda3c89e8259d and the Discord at discord.gg/RJdqQ9n Introduction Initial structure Structure Q&A send and recv send/recv Q&A Does it work? Zero senders Q&A Why does it hang? Implementation Q&A Synchronous channels Batch recv optimization Channel flavors Flavor Q&A Other implementations Future-aware channels Where next? Channels Q&A You can find crossbeam-channel at github.com/crossbeam-rs/crossbeam/tree/master/crossbeam-chan…, and flume at github.com/zesterer/flume/. You can watch the live version with comments at youtube.com/watch?v=JvBUKsFIUKw

Why it's here

2 people recommend this

What people say. Highly recommended as an excellent, hands-on guide to understanding and implementing concurrency channels in Rust.

u/InsanityBlossomin r/rust • Recommends

On “Does anyone know the overhead involved in sending things through channels?”

Jon made a great video where he explained and implemented a simple channel. Highly suggest checking out. link to this video

u/TheSpoolerzin r/rust • Recommends

On “Changing variables between threads”

Try channels. Jon Gjengset just posted a link to this video about them, check it out.