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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
mox692
February 13, 2025
Programming
0
46
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
20
Instrumenting Async Runtime
kimuramotoyuki
0
130
Other Decks in Programming
See All in Programming
2026年は Rust 置き換えが流行る! / 20260220-niigata-5min-tech
girigiribauer
0
220
Claude Code の Skill で複雑な既存仕様をすっきり整理しよう
yuichirokato
1
310
Go1.26 go fixをプロダクトに適用して困ったこと
kurakura0916
0
330
RubyとGoでゼロから作る証券システム: 高信頼性が求められるシステムのコードの外側にある設計と運用のリアル
free_world21
0
220
社内規程RAGの精度を73.3% → 100%に改善した話
oharu121
13
7.7k
Unity6.3 AudioUpdate
cova8bitdots
0
110
Event Storming
hschwentner
3
1.3k
15年目のiOSアプリを1から作り直す技術
teakun
1
610
LangChain4jとは一味違うLangChain4j-CDI
kazumura
1
150
今、アーキテクトとして 品質保証にどう関わるか
nealle
0
200
PJのドキュメントを全部Git管理にしたら、一番喜んだのはAIだった
nanaism
0
240
Head of Engineeringが現場で回した生産性向上施策 2025→2026
gessy0129
0
210
Featured
See All Featured
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.1k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
0
170
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
430
A designer walks into a library…
pauljervisheath
210
24k
The World Runs on Bad Software
bkeepers
PRO
72
12k
ラッコキーワード サービス紹介資料
rakko
1
2.5M
Crafting Experiences
bethany
1
81
GraphQLの誤解/rethinking-graphql
sonatard
75
11k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
660
Ruling the World: When Life Gets Gamed
codingconduct
0
160
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
140
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
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