Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Implementing Async MPMC Channel in Rust
Search
mox692
February 13, 2025
Programming
53
0
Share
Implementing Async MPMC Channel in Rust
mox692
February 13, 2025
More Decks by mox692
See All by mox692
Bug-Free Concurrency in Rust
kimuramotoyuki
0
26
Instrumenting Async Runtime
kimuramotoyuki
0
140
Other Decks in Programming
See All in Programming
Signal Forms: Beyond the Basics @ngBaguette 2026 in Paris
manfredsteyer
PRO
0
210
技術記事、AIに書かせるか、自分で書くか? 〜それでも私が自分の手で書く理由〜 / #QiitaConference
jnchito
2
1.2k
Transactional Change Stream Processing With Debezium and Apache Flink
gunnarmorling
1
150
運用エージェントは "作る" から "育てる" へ - 記憶と自己進化の3層設計パターン / self-evolving-agents-three-layer-agent-design
gawa
12
3.4k
今さら聞けないCancellationToken
htkym
0
210
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3.1k
Migrations : C'est une question d'hygiène !
vinceamstoutz
0
2.9k
JavaDoc 再入門
nagise
0
250
関係性から理解する"同一性"の型用語たち
pvcresin
2
630
脅威をエンジニアリングの糧にして――現場編 / Turning Threats into Engineering Fuel — Field Edition
nrslib
0
240
さぁV100、メモリをお食べ・・・
nilpe
0
120
Oxlintのカスタムルールの現況
syumai
5
970
Featured
See All Featured
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
62
54k
Tell your own story through comics
letsgokoyo
1
940
Optimising Largest Contentful Paint
csswizardry
37
3.7k
Color Theory Basics | Prateek | Gurzu
gurzu
0
320
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
380
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
70
39k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
65
55k
Balancing Empowerment & Direction
lara
6
1.1k
Prompt Engineering for Job Search
mfonobong
0
330
Accessibility Awareness
sabderemane
1
130
Unsuck your backbone
ammeep
672
58k
Transcript
Implementing Async MPMC Channel in Rust Motoyuki Kimura 1
MPMC Channel? • Multi Producer Multi Consumer Channel • i.e.
have multiple senders and multiple receivers 2 Sender Sender Sender Receiver Receiver
Channel Types • Bounded / Unbounded • Async / Sync
• SPSC, MPSC, MPMC 3
Prior Art 4 kind bounded / unbounded sync / async
std::mpmc mpmc, mpsc, etc both sync crossbeam mpmc, mpsc, etc both sync async_channel mpmc both async kanal mpmc both sync/async Go channel mpmc both async
How do channels work? 5
• Allocate a fixed length area Bounded 6 Sender Receiver
Bounded 7 AAA BBB CCC Sender Receiver sender.send(CCC)
Bounded 8 BBB CCC Sender AAA Receiver
Bounded 9 HHH DDD EEE FFF GGG Sender CCC Receiver
Bounded 10 Sender Receiver • If there is no available
data, reader would block Block!
Bounded 11 HHH III CCC DDD EEE FFF GGG Sender
Receiver • If receiver is too slow, sender would block Block!
Bounded 12 HHH DDD EEE FFF GGG Sender Sender Sender
Receiver Receiver • Actually, multiple senders and receivers work concurrently
Implementation Details 13
How to achieve block/unblock? 14
Block / Unblock 15 • Sync channel ◦ thread api
(park, unpark) • Async channel ◦ waker api
Block / Unblock 16 Sender Receiver Block!
Block / Unblock 17 Sender Receiver Waker Waker list •
When block happens, store waker somewhere
Block / Unblock 18 CCC Sender Receiver Waker1 Waker list
• When block happens, store waker somewhere Pop from list
Depth of Wakerlist … 🚀 19 • For wakerlist, intrusive
linked list would be much performant ◦ What are intrusive linked lists? ◦ new internal semaphore based on intrusive lists
How to test concurrent code base? 20
How to test concurrent code base? 21 • Multi threaded
• Complex synchronization • Atomic Operations
How to test concurrent code base? 22
How to test concurrent code base? 23 Detect Deadlocks! 🙌
About Loom internals … 24 Video 🎥: https://youtu.be/-MRCgyiCxWU?si=a4NNwSxVgke6AFwZ Slide 📝:
https://speakerdeck.com/kimuramotoyuki/bug-free-concurrency-in-rust
25 https://crates.io/crates/chunnel
Thank you! 26