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
19
Instrumenting Async Runtime
kimuramotoyuki
0
120
Other Decks in Programming
See All in Programming
生成AIを利用するだけでなく、投資できる組織へ
pospome
2
450
なぜSQLはAIぽく見えるのか/why does SQL look AI like
florets1
0
250
KIKI_MBSD Cybersecurity Challenges 2025
ikema
0
150
PC-6001でPSG曲を鳴らすまでを全部NetBSD上の Makefile に押し込んでみた / osc2025hiroshima
tsutsui
0
210
React 19でつくる「気持ちいいUI」- 楽観的UIのすすめ
himorishige
11
5.4k
まだ間に合う!Claude Code元年をふりかえる
nogu66
5
940
rack-attack gemによるリクエスト制限の失敗と学び
pndcat
0
110
Canon EOS R50 V と R5 Mark II 購入でみえてきた最近のデジイチ VR180 事情、そして VR180 静止画に活路を見出すまで
karad
0
140
CSC307 Lecture 02
javiergs
PRO
1
760
ThorVG Viewer In VS Code
nors
0
690
CSC307 Lecture 03
javiergs
PRO
1
480
SQL Server 2025 LT
odashinsuke
0
160
Featured
See All Featured
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
420
Heart Work Chapter 1 - Part 1
lfama
PRO
5
35k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
1
59
Site-Speed That Sticks
csswizardry
13
1k
Designing for Timeless Needs
cassininazir
0
120
A Tale of Four Properties
chriscoyier
162
24k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.8k
Testing 201, or: Great Expectations
jmmastey
46
7.9k
Typedesign – Prime Four
hannesfritz
42
2.9k
Paper Plane (Part 1)
katiecoart
PRO
0
3.1k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.3k
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