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
5 分でやる Rust Concurrency in Action
Search
Ryo Okubo
June 27, 2017
Programming
1
440
5 分でやる Rust Concurrency in Action
RustのLT会! Rust入門者の集い #3 で話した資料です。
https://rust.connpass.com/event/56276/
Ryo Okubo
June 27, 2017
Tweet
Share
More Decks by Ryo Okubo
See All by Ryo Okubo
メルカリ・メルペイの成長を支える データ基盤とはどんなものか
syucream
7
6.9k
バッチとストリーミング、それぞれの障害に立ち向かう
syucream
3
3.6k
How Scala works at Mercari
syucream
2
1k
Production-ready stream data pipeline in Merpay, Inc
syucream
2
13k
データとML周辺エンジニアリン グを考える会 #2 イントロ
syucream
0
630
マイクロサービスにおける ログ収集の課題と取り組み
syucream
7
2.7k
Stream Data Pipeline for Microservices in Merpay
syucream
6
1.2k
メルペイにおける、マイクロサービスに寄り添うログ収集基盤 / Microservices-frendly Data Pipeline
syucream
0
18k
Merpay のデータ収集基盤
syucream
5
1.1k
Other Decks in Programming
See All in Programming
gen_statem - OTP's Unsung Hero
whatyouhide
1
190
Qiita Bash
mercury_dev0517
1
190
Building Scalable Mobile Projects: Fast Builds, High Reusability and Clear Ownership
cyrilmottier
2
260
Going Structural with Named Tuples
bishabosha
0
200
Boost Your Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
1.2k
Kamal 2 – Get Out of the Cloud
aleksandrov
1
180
Compose Hot Reload is here, stop re-launching your apps! (Android Makers 2025)
zsmb
1
480
生成AIを使ったQAアプリケーションの作成 - ハンズオン補足資料
oracle4engineer
PRO
3
190
The Weight of Data: Rethinking Cloud-Native Systems for the Age of AI
hollycummins
0
270
Devinのメモリ活用の学びを自社サービスにどう組み込むか?
itarutomy
0
2k
サービスクラスのありがたみを発見したときの思い出 #phpcon_odawara
77web
4
630
エンジニア未経験が最短で戦力になるためのTips
gokana
0
260
Featured
See All Featured
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
4 Signs Your Business is Dying
shpigford
183
22k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
227
22k
Measuring & Analyzing Core Web Vitals
bluesmoon
7
390
Stop Working from a Prison Cell
hatefulcrawdad
268
20k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
23
2.6k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
178
53k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
233
17k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
32
5.1k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.6k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Transcript
5 分でやる Rust Concurrency in Ac0on @syu_cream
わたしはだれ • @syu_cream – ウェッブサービスの裏側を支える技術者 – 趣味でmrubyの薄い本やC++のコード書いてます
今日のお話 • Rust でマルチスレッドプログラミングするのって • C++ でやるより楽だよねというはなし • 時間も限られてるし mutex
についてのみ • 題材としてスレッド毎にvectorに要素追加してみる – GitHub に今日話すソースコードあります – h<ps://github.com/syucream/rust_cia
C++ で書く場合(データ競合起こす版) • コンパイルは通る – ただし未定義動作になる
C++ で書く場合 • ロックを取ることでデータ競合を避ける
Rust で書く場合(データ競合起こす版1) • コンパイルが…
Rust で書く場合(データ競合起こす版1) • コンパイルが…通らない! – 複数のスレッドに変数をborrowしようとしてるため
Rust で書く場合(データ競合起こす版2) • じゃあ Arc で参照をcloneしてborrowしよう! • これでコンパイルが…
Rust で書く場合(データ競合起こす版2) • じゃあ Arc で参照をcloneしてborrowしよう! • これでコンパイルが…通らない! – Arc<T> の変数は複数スレッドから変更できない
Rust で書く場合 • Mutex<T> を使う! – lock() でロックを取って変更する
マルチスレッドプログラミングにおける C++ vs Rust • C++ – C++11以降ならthread,mutexが標準で使えて便利 – データ競合についてはプログラマが気をつける必要あり
• Rust – データ競合が起こる場合コンパイル時にエラーになる
Rustでも競合状態は避けきれない • 以下のコードはデッドロックを起こす…
まとめ • Rust でマルチスレッドプログラミングするのって – コンパイル時のチェックが手厚いので • C++ でやるより楽だよねというはなし –
ただし万能なわけではないよ