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
ComposeでWebアプリを作る技術
tbsten
0
130
Cursor/Devin全社導入の理想と現実
saitoryc
28
21k
Improve my own Ruby
sisshiki1969
0
100
KawaiiLT 登壇資料 キャリアとモチベーション
hiiragi
0
160
音声プラットフォームのアーキテクチャ変遷から学ぶ、クラウドネイティブなバッチ処理 (20250422_CNDS2025_Batch_Architecture)
thousanda
0
390
The Implementations of Advanced LR Parser Algorithm
junk0612
2
1.3k
Golangci-lint v2爆誕: 君たちはどうすべきか
logica0419
1
230
Making TCPSocket.new "Happy"!
coe401_
1
3.1k
Deoptimization: How YJIT Speeds Up Ruby by Slowing Down / RubyKaigi 2025
k0kubun
2
1.9k
「理解」を重視したAI活用開発
fast_doctor
0
270
KANNA Android の技術的課題と取り組み
watabee
0
190
Ruby's Line Breaks
yui_knk
4
2.8k
Featured
See All Featured
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
30
2.3k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
Building Flexible Design Systems
yeseniaperezcruz
329
39k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.7k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
357
30k
Building Better People: How to give real-time feedback that sticks.
wjessup
367
19k
Facilitating Awesome Meetings
lara
54
6.3k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.7k
Done Done
chrislema
184
16k
How to Ace a Technical Interview
jacobian
276
23k
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++ でやるより楽だよねというはなし –
ただし万能なわけではないよ