Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
5 分でやる Rust Concurrency in Action
Search
Ryo Okubo
June 27, 2017
Programming
500
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
5 分でやる Rust Concurrency in Action
RustのLT会! Rust入門者の集い #3 で話した資料です。
https://rust.connpass.com/event/56276/
Ryo Okubo
June 27, 2017
Transcript
13 slides
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++ でやるより楽だよねというはなし –
ただし万能なわけではないよ
More Decks by Ryo Okubo
See All by Ryo Okubo
小さな修正に、開発者が張り付かなくてよくなるまで 〜UbieのSoftware Factoryで進める、実装・検証・出荷の自動化〜(draft版)
syucream
0
26
気軽に使える"情報のハブ"としてのNotion活用 〜フロー情報の集積点 と、 Claude Code × Notion AI〜
syucream
1
330
UbieのAIパートナーを支えるコンテキストエンジニアリング実践
syucream
3
1.7k
メルカリ・メルペイの成長を支える データ基盤とはどんなものか
syucream
6
7.5k
バッチとストリーミング、それぞれの障害に立ち向かう
syucream
3
3.9k
How Scala works at Mercari
syucream
2
1.2k
Production-ready stream data pipeline in Merpay, Inc
syucream
2
13k
データとML周辺エンジニアリン グを考える会 #2 イントロ
syucream
0
710
マイクロサービスにおける ログ収集の課題と取り組み
syucream
7
2.9k
Other Decks in Programming
See All in Programming
Materialが消えた日 〜真っ白なFlutterキャンバスにRenderObjectで絵を描く〜
umigishiaoi
0
170
小さなアプリを作って公開するまで
onozaty
0
260
地方こそサーバーレス — 10年続けた、顔が見えるチームで確かな基盤を / Serverless Matters Most in Regional Areas — 10 Years of Building Reliable Foundations with Close-Knit Teams
seike460
PRO
2
520
Apache Airflow Introduction
leew
1
100
[Kotlin Fest 2026] eBPF Tracing for Kotlin
takehaya
1
410
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
440
Secure Your Coding Agent Like It’s Malware (v1.5) 🇬🇧 @Code.talks 2026
richargh
0
210
社内AIエージェント「Askワンバン」における コストチューニングの取り組み
t0yohei
0
180
AppFunctionsの内部実装を紐解く
hiroaki404
1
120
SODA - FACT BOOK(JP)
sodainc
1
40k
ruby/uri meets WHATWG
jinroq
0
150
AIコーディングをセッションで終わらせない: PHPライブラリ開発におけるコンテキスト承継設計
ickx
0
110
Featured
See All Featured
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
650
The Curious Case for Waylosing
cassininazir
1
630
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.5k
Believing is Seeing
oripsolob
1
290
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
We Are The Robots
honzajavorek
0
460
WENDY [Excerpt]
tessaabrams
15
41k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
2
410
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
56
3.5k
Git: the NoSQL Database
bkeepers
PRO
433
67k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
470