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
protect_mutable_state_in_concurrent_Swift_applications.pdf
Search
ohayoukenchan
June 25, 2021
Programming
0
1.1k
protect_mutable_state_in_concurrent_Swift_applications.pdf
ohayoukenchan
June 25, 2021
Tweet
Share
More Decks by ohayoukenchan
See All by ohayoukenchan
iOSDC2021 知られざる課金ステータス
ohayoukenchan
1
6.9k
iOSDC2018_ohayou_kenchan.pdf
ohayoukenchan
4
3.8k
Other Decks in Programming
See All in Programming
架空のコンペ_スクワットフォーム判別コンペの解法
cpptake
0
430
私がエッジを使う理由
chimame
9
3.6k
GitHub Copilot Tips and Tricks
yuichielectric
2
240
RISC-V カスタムのためのツールチェーン拡張 ― GNU Binutils と GCC の拡張・コミュニティへの参加編 (未完成版)
a4lg
0
190
htmx is fun!
codehex
2
160
phpunit/php-code-coverageって何をしてるんだ #phperkaigi
o0h
PRO
2
190
Learning PHP and Static Analysis with PHP Parser
inouehi
1
220
期限が近づいてきた!Privacy Manifests対応
ryunakayama
5
3k
PHPアプリケーションのスケーラビリティと 信頼性を革新する nginx+ngx_mrubyとGoの融合
pyama86
2
220
品質が高いコードって何?Rev2.1
ickx
1
380
導入から5年が経って見えた Datadog APM 運用の課題
bgpat
1
480
decksh - a little language for decks
ajstarks
4
18k
Featured
See All Featured
KATA
mclloyd
14
11k
Fantastic passwords and where to find them - at NoRuKo
philnash
35
2.4k
The Straight Up "How To Draw Better" Workshop
denniskardys
227
130k
Building a Scalable Design System with Sketch
lauravandoore
455
32k
The Cost Of JavaScript in 2023
addyosmani
13
3.7k
How to Ace a Technical Interview
jacobian
272
22k
Teambox: Starting and Learning
jrom
126
8.3k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
355
22k
Why Our Code Smells
bkeepers
PRO
330
56k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
6
930
VelocityConf: Rendering Performance Case Studies
addyosmani
319
23k
Product Roadmaps are Hard
iamctodd
43
9.6k
Transcript
protect mutable state in concurrent Swift applications sento_kun (ohayoukenchan) ママリiOSエンジニア募集中だよ
この話の流れ - data races - actors in Swift(Actorってなぁに) - actor
reentrancy(再入性) - actor isolation(Actorの分離) - main actor(メインスレッドでの非同期処理)
いきなりですが Data Races とは?
None
共有された 可変型の状態が必要 とされる場合がある
共有された可変型の状態 をうまく同期させたい
actors in Swift
Actors - Actorsは独自の状態を持ち、その状態は他のプログラムから隔離されて います。 - Actorsにアクセスするには、Actorsを経由するしかありません。 - Actorsを経由するときはいつでも、Actorsの同期メカニズムによって、他の コードが同時にActorsの状態にアクセスしないことが保証されます。 -
ロックやシリアルディスパッチキューを手動で使用したときに得られるのと 同じ相互排除特性が得られます
Data Races データ競合(data race)は、マルチスレッド ・プログラム実装上の問題
One will get there first, and the other will have
to wait its turn.
actors in Swift
Actor reentrancy
actors in Swift
None
Actor Isolation
protocol conformances
Await
Await
None
None
Closures
None
None
actor isolation and data
None
None
Sendable
None
None
None
Main Actor
thinking about main thread
None
None
まとめもりー - mutableな状態への同時アクセスを防ぐことでデータ競合を防ぐ - value semantic(letとかstruct)みたいなimmutableなデータと Actors(mutable な状態への同時アクセスできる)を使って非同期処理 を設計しよう -
Actorの分離(内側にあるか外側にあるか)を考慮する - メインスレッドで非同期処理をすることを保証するため DispatchQueue.mainのかわりにMainActorを使う
おわり
Data Races データ競合(data race)は、マルチスレッド ・プログラム実装上の問題