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
データ競合と対策
Search
まりも
May 16, 2024
Programming
30
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
データ競合と対策
非同期処理を非常に難しいものにしている原因の一つである、データ競合と現在考えられているその対策について解説します。
まりも
May 16, 2024
More Decks by まりも
See All by まりも
オブジェクトモデルと関係モデルの設計
hrmstrsmgs
0
64
メンタルモデルから見るオブジェクト設計
hrmstrsmgs
1
430
技術的負債
hrmstrsmgs
1
460
よい設計のプログラムを作るには
hrmstrsmgs
0
140
歴史から理解するJavaScript
hrmstrsmgs
0
110
論理的な考え方
hrmstrsmgs
0
120
論理的な話し合いはなぜ必要か
hrmstrsmgs
0
85
腕のある技術者はなぜ
hrmstrsmgs
0
160
疑似乱数の生成
hrmstrsmgs
0
82
Other Decks in Programming
See All in Programming
sbt 2.0: takeoff
eed3si9n
0
160
Apple Intelligence を用いた個人情報誤送信防止、及びユーザーリクエスト体験の改善について
yukiny
0
350
UPDATE をやめる — EF Core でマスタをバージョン管理する
panda728
PRO
0
1.2k
Agents on Rails - Rails at Scale 2026
irinanazarova
0
560
外から家のPCの電源入れたい!をPHPで解決する
kawashimo0
1
130
Event is what happens
moro
2
770
機械に任せるテスト、人が見るテスト ⽣成AIで引き直した、運⽤保守フェーズの線引き
dske104
0
190
R8 の設定見直しでアプリサイズ削減
andpad
0
220
Railsバージョンを4倍にした話
optim
0
350
AIに “答え“を書かせるのを やめてみた
___akari11
0
120
RAG の “R” を Swift で覗いてみる 〜「意味から探す」検索の仕組み〜
nao_randd
0
160
[2026-09-26]空論ジェネリックプロセス~テスト資産とAIで紡ぐ、再現可能なパフォーマンスチューニングの話~
tosite
0
270
Featured
See All Featured
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
990
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
480
The Limits of Empathy - UXLibs8
cassininazir
2
720
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
330
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
630
Fireside Chat
paigeccino
43
4.1k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
3
3.9k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
360
The Curious Case for Waylosing
cassininazir
1
570
BBQ
matthewcrist
90
10k
Navigating Team Friction
lara
192
16k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.5k
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#