$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
データ競合と対策
Search
まりも
May 16, 2024
Programming
0
14
データ競合と対策
非同期処理を非常に難しいものにしている原因の一つである、データ競合と現在考えられているその対策について解説します。
まりも
May 16, 2024
Tweet
Share
More Decks by まりも
See All by まりも
メンタルモデルから見るオブジェクト設計
hrmstrsmgs
0
210
技術的負債
hrmstrsmgs
0
230
よい設計のプログラムを作るには
hrmstrsmgs
0
77
歴史から理解するJavaScript
hrmstrsmgs
0
58
論理的な考え方
hrmstrsmgs
0
58
論理的な話し合いはなぜ必要か
hrmstrsmgs
0
31
腕のある技術者はなぜ
hrmstrsmgs
0
75
疑似乱数の生成
hrmstrsmgs
0
40
構造化プログラミング
hrmstrsmgs
0
150
Other Decks in Programming
See All in Programming
Findy AI+の開発、運用におけるMCP活用事例
starfish719
0
1.4k
これならできる!個人開発のすゝめ
tinykitten
PRO
0
120
Claude Codeの「Compacting Conversation」を体感50%減! CLAUDE.md + 8 Skills で挑むコンテキスト管理術
kmurahama
1
560
Navigating Dependency Injection with Metro
l2hyunwoo
1
150
Canon EOS R50 V と R5 Mark II 購入でみえてきた最近のデジイチ VR180 事情、そして VR180 静止画に活路を見出すまで
karad
0
130
dotfiles 式年遷宮 令和最新版
masawada
1
800
チームをチームにするEM
hitode909
0
350
안드로이드 9년차 개발자, 프론트엔드 주니어로 커리어 리셋하기
maryang
1
130
大体よく分かるscala.collection.immutable.HashMap ~ Compressed Hash-Array Mapped Prefix-tree (CHAMP) ~
matsu_chara
2
220
FluorTracer / RayTracingCamp11
kugimasa
0
240
UIデザインに役立つ 2025年の最新CSS / The Latest CSS for UI Design 2025
clockmaker
18
7.6k
リリース時」テストから「デイリー実行」へ!開発マネージャが取り組んだ、レガシー自動テストのモダン化戦略
goataka
0
130
Featured
See All Featured
Into the Great Unknown - MozCon
thekraken
40
2.2k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
32
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
46
4 Signs Your Business is Dying
shpigford
186
22k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
WCS-LA-2024
lcolladotor
0
380
How to make the Groovebox
asonas
2
1.8k
Designing for Performance
lara
610
69k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
310
Build your cross-platform service in a week with App Engine
jlugia
234
18k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandezseo
0
83
How to train your dragon (web standard)
notwaldorf
97
6.4k
Transcript
データ競合と対策
データ競合 public void 預金額を処理する() { var 移動金額 = 預金額1 /
2; this.預金額2 = this.預金額2 - 移動金額; this.預金額1 = this.預金額1 + 移動金額; }
データ競合 public void Increment() { this.Count++; }
データ競合 public void Add(int i) { list.Add(i); }
対策(LOCK) class 預金口座 { decimal 残高; private Object thisLock =
new Object(); public void 預金を下す(decimal 金額) { lock (thisLock) { if (金額> 残高) { throw new Exception("不足しています"); } 残高 -=金額; } } }
対策(LOCK) データ競合 全ての場合に有効 デッドロックに気を付ける 処理 順次、反復、分岐のすべて 利点 簡単 問題点 ロックをかけた部分は並列処理ができない
アムダールの法則を考えると結構大きな問題なんじゃ? 対応言語 ほぼすべての言語
対策(イミュータブル) class 総額 { const int 残高; public: 総額(const int
残高) :残高(残高) {} const 総額 下す(const int 総額) const; };
対策(イミュータブル) データ競合 そもそも起きない 処理 順次、反復、分岐のすべて 利点 データ競合はおきない 問題点 関数型言語っぽい書き方に直さないといけない 対応言語
関数型言語、C++、C#(8以降?)、 オブジェクト指向言語(イミュータブルになるよう気を付けて書けば可能)
対策(ASYNC/AWAIT) データ競合 データ競合がない場合に利用 行数で全体の8割くらいはデータ競合ないんじゃ? 処理 順次、反復、分岐のすべて 利点 同期プログラムと全く同じ感覚で使える 問題点 データ競合に対応できない
データ競合対策は別に必要 対応言語 C#,Visual Basic,F#,Typescript,Python,Ecmascript(2017)C++(17には入らない?)
対策(PLINQなど) var result = from item in list.AsParallel()
where item < 100 select Sqrt(item);
参考に普通のLINQ var result = from item in list
where item < 100 select Sqrt(item);
対策(PLINQなど) データ競合 リストのデータ一つ一つに対して処理する場合 処理 反復のみ 利点 簡単 問題点 多数データを並列の場合しか使えない 対応言語
C#,Java,Scala
対策(REACTIVE EXTENSIONS) データ競合 リストのデータ一つ一つに対して処理する場合 イベントストリーム 処理 基本的には反復 工夫すれば順次、反復、分岐のすべて 利点 比較的簡単
対応できる処理も多い 問題点 多数データとイベントを非同期で扱うときしか使えない アムダールの法則を考えると結構重要な欠点なんじゃ? 対応言語 C#,Visual Basic,Swift,JavaScript,Java
対策(ACTOR) データ競合 対策済み 処理 順次、反復、分岐のすべて ただし非同期処理は気を付けて扱う必要がある 利点 比較的簡単 問題点 非同期処理をしっかり意識しないと実装できない
対応言語 Erlang,Scala,Elixer,C++,C#
対策(スレッド所有権) データ競合 対策済み Actorより深い対応 処理 非同期処理は気を付けて扱う必要がある Actorと同じ 利点 比較的簡単 Actorの一種
問題点 非同期処理をしっかり意識しないと実装できない 対応言語 Ruby(guild),Pony
対策(STM) データ競合 対策済み 処理 非同期処理は気を付けて扱う必要がある 利点 比較的簡単 割と難しいといううわさも 問題点 非同期処理をしっかり意識しないと実装できない
対応言語 C++、F#