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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
まりも
May 16, 2024
Programming
27
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
61
メンタルモデルから見るオブジェクト設計
hrmstrsmgs
0
410
技術的負債
hrmstrsmgs
1
440
よい設計のプログラムを作るには
hrmstrsmgs
0
130
歴史から理解するJavaScript
hrmstrsmgs
0
100
論理的な考え方
hrmstrsmgs
0
120
論理的な話し合いはなぜ必要か
hrmstrsmgs
0
82
腕のある技術者はなぜ
hrmstrsmgs
0
160
疑似乱数の生成
hrmstrsmgs
0
77
Other Decks in Programming
See All in Programming
App Storeの外へ──日本のiOSサイドローディング入門 for iOSDC Japan 2026
yuukiw00w
0
210
選挙速報を多くのユーザーへ 届ける Live Activities 設計
hamayokokuririn
0
140
How I Stole PSI from Android Studio - DroidKaigi2026
worker8
0
130
速く作れる。その次は、速く確かめられる開発へ 〜AIネイティブ開発を支える、Shift Down〜 / Can build fast. Next, moving to development where we can verify fast.
rkaga
4
2.8k
新卒PdEのリアル
ryu1013
1
500
AWS DevOps Agentで インシデント対応をAIに任せたい
honmarkhunt
7
2.9k
AHC070解法紹介
eijirou
0
120
スマートフォンでモールス信号を送受信する 〜スマートフォンのLEDとカメラで作る光通信の設計と実装〜
atsuki_seo
0
120
巨大モノリシックアプリ モダン化大作戦
ktcryomm
0
1k
モデルのリファクタリングが難しいと思ったら、そもそも複雑だったのはビジネス仕様だった ? / is-the-business-domain-the-real-complexity
hatsu38
0
260
Webの地図
yosuke_furukawa
PRO
6
4.5k
Go × SIMDで高速化するベクトル検索 ~ルーフラインモデルでSIMDが効く境界を探れ! ~
po3rin
1
1k
Featured
See All Featured
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
280
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
700
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
200
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
280
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.3k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
368
27k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Building a Scalable Design System with Sketch
lauravandoore
464
34k
Building an army of robots
kneath
307
46k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
690
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
540
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#