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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Ryo Okubo
June 27, 2017
Programming
1
480
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
UbieのAIパートナーを支えるコンテキストエンジニアリング実践
syucream
3
1.4k
メルカリ・メルペイの成長を支える データ基盤とはどんなものか
syucream
7
7.3k
バッチとストリーミング、それぞれの障害に立ち向かう
syucream
3
3.8k
How Scala works at Mercari
syucream
2
1.1k
Production-ready stream data pipeline in Merpay, Inc
syucream
2
13k
データとML周辺エンジニアリン グを考える会 #2 イントロ
syucream
0
670
マイクロサービスにおける ログ収集の課題と取り組み
syucream
7
2.8k
Stream Data Pipeline for Microservices in Merpay
syucream
6
1.3k
メルペイにおける、マイクロサービスに寄り添うログ収集基盤 / Microservices-frendly Data Pipeline
syucream
0
18k
Other Decks in Programming
See All in Programming
Swift ConcurrencyでよりSwiftyに
yuukiw00w
0
270
DevinとClaude Code、SREの現場で使い倒してみた件
karia
1
1.1k
AI活用のコスパを最大化する方法
ochtum
0
160
米国のサイバーセキュリティタイムラインと見る Goの暗号パッケージの進化
tomtwinkle
2
610
ふつうのRubyist、ちいさなデバイス、大きな一年 / Ordinary Rubyists, Tiny Devices, Big Year
chobishiba
1
470
What Spring Developers Should Know About Jakarta EE
ivargrimstad
0
400
CS教育のDX AIによる育成の効率化
niftycorp
PRO
0
140
コーディングルールの鮮度を保ちたい / keep-fresh-go-internal-conventions
handlename
0
210
RubyとGoでゼロから作る証券システム: 高信頼性が求められるシステムのコードの外側にある設計と運用のリアル
free_world21
0
310
Fundamentals of Software Engineering In the Age of AI
therealdanvega
2
260
OTP を自動で入力する裏技
megabitsenmzq
0
120
ふつうの Rubyist、ちいさなデバイス、大きな一年
bash0c7
0
1k
Featured
See All Featured
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
9.9k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
78
Faster Mobile Websites
deanohume
310
31k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
Paper Plane (Part 1)
katiecoart
PRO
0
5.7k
Bash Introduction
62gerente
615
210k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
790
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
60
43k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
310
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
200
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.8k
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++ でやるより楽だよねというはなし –
ただし万能なわけではないよ