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
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
Rails Girls Tokyo 18th GMO Pepabo Sponsor Talk
yutokyokutyo
0
210
PJのドキュメントを全部Git管理にしたら、一番喜んだのはAIだった
nanaism
0
240
CSC307 Lecture 13
javiergs
PRO
0
310
Go Conference mini in Sendai 2026 : Goに新機能を提案し実装されるまでのフロー徹底解説
yamatoya
0
530
What Spring Developers Should Know About Jakarta EE
ivargrimstad
0
260
Claude Code の Skill で複雑な既存仕様をすっきり整理しよう
yuichirokato
1
310
Python’s True Superpower
hynek
0
200
CSC307 Lecture 15
javiergs
PRO
0
230
Codexに役割を持たせる 他のAIエージェントと組み合わせる実務Tips
o8n
3
1.1k
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
410
RAGでハマりがちな"Excelの罠"を、データの構造化で突破する
harumiweb
9
2.6k
AWS×クラウドネイティブソフトウェア設計 / AWS x Cloud-Native Software Design
nrslib
10
2.5k
Featured
See All Featured
WCS-LA-2024
lcolladotor
0
470
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.6k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
52k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
61k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
620
Ruling the World: When Life Gets Gamed
codingconduct
0
160
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.6k
Optimising Largest Contentful Paint
csswizardry
37
3.6k
Site-Speed That Sticks
csswizardry
13
1.1k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
8.8k
Accessibility Awareness
sabderemane
0
73
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