Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
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
43
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
17
Instrumenting Async Runtime
kimuramotoyuki
0
120
Other Decks in Programming
See All in Programming
チームをチームにするEM
hitode909
0
390
Navigating Dependency Injection with Metro
l2hyunwoo
1
190
Claude Codeの「Compacting Conversation」を体感50%減! CLAUDE.md + 8 Skills で挑むコンテキスト管理術
kmurahama
1
640
実はマルチモーダルだった。ブラウザの組み込みAI🧠でWebの未来を感じてみよう #jsfes #gemini
n0bisuke2
3
1.3k
AtCoder Conference 2025「LLM時代のAHC」
imjk
2
590
Developing static sites with Ruby
okuramasafumi
0
330
Cap'n Webについて
yusukebe
0
150
組み合わせ爆発にのまれない - 責務分割 x テスト
halhorn
1
160
perlをWebAssembly上で動かすと何が嬉しいの??? / Where does Perl-on-Wasm actually make sense?
mackee
0
140
안드로이드 9년차 개발자, 프론트엔드 주니어로 커리어 리셋하기
maryang
1
140
Deno Tunnel を使ってみた話
kamekyame
0
250
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
370
Featured
See All Featured
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
1
410
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
120
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
3.4k
Navigating Team Friction
lara
191
16k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.1k
Practical Orchestrator
shlominoach
190
11k
4 Signs Your Business is Dying
shpigford
186
22k
A Modern Web Designer's Workflow
chriscoyier
698
190k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
73
The Mindset for Success: Future Career Progression
greggifford
PRO
0
200
Everyday Curiosity
cassininazir
0
110
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
30
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