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
0
15
Implementing Async MPMC Channel in Rust
mox692
February 13, 2025
Tweet
Share
More Decks by mox692
See All by mox692
Bug-Free Concurrency in Rust
kimuramotoyuki
0
15
Instrumenting Async Runtime
kimuramotoyuki
0
76
Other Decks in Programming
See All in Programming
第9回 情シス転職ミートアップ 株式会社IVRy(アイブリー)の紹介
ivry_presentationmaterials
1
260
CursorはMCPを使った方が良いぞ
taigakono
1
220
Azure AI Foundryではじめてのマルチエージェントワークフロー
seosoft
0
150
GraphRAGの仕組みまるわかり
tosuri13
8
530
なんとなくわかった気になるブロックテーマ入門/contents.nagoya 2025 6.28
chiilog
1
260
Google Agent Development Kit でLINE Botを作ってみた
ymd65536
2
220
Result型で“失敗”を型にするPHPコードの書き方
kajitack
5
590
ソフトウェア品質を数字で捉える技術。事業成長を支えるシステム品質の マネジメント
takuya542
1
9.2k
AIと”コードの評価関数”を共有する / Share the "code evaluation function" with AI
euglena1215
1
130
Cursor AI Agentと伴走する アプリケーションの高速リプレイス
daisuketakeda
1
130
生成AIコーディングとの向き合い方、AIと共創するという考え方 / How to deal with generative AI coding and the concept of co-creating with AI
seike460
PRO
1
350
NPOでのDevinの活用
codeforeveryone
0
760
Featured
See All Featured
Rebuilding a faster, lazier Slack
samanthasiow
82
9.1k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
How to train your dragon (web standard)
notwaldorf
94
6.1k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
130
19k
Balancing Empowerment & Direction
lara
1
400
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
8
680
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
29
9.5k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
657
60k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
35
2.4k
Typedesign – Prime Four
hannesfritz
42
2.7k
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