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_appli...
Search
ohayoukenchan
June 25, 2021
Programming
0
1.3k
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
7.9k
iOSDC2018_ohayou_kenchan.pdf
ohayoukenchan
4
4.1k
Other Decks in Programming
See All in Programming
バイラテラルアップサンプリング
fadis
3
300
Носок на сок
bo0om
0
1.2k
Making TCPSocket.new "Happy"!
coe401_
1
3.2k
複雑なフォームの jotai 設計 / Designing jotai(state) for Complex Forms #layerx_frontend
izumin5210
6
1.5k
マイコンでもRustのtestがしたい/KernelVM Kansai 11
tnishinaga
0
780
The Missing Link in Angular’s Signal Story: Resource API and httpResource
manfredsteyer
PRO
0
140
七輪ライブラリー: Claude AI で作る Next.js アプリ
suneo3476
1
190
プロダクトエンジニアのしごと 〜 受託 × 高難度を乗り越えるOptium開発 〜
algoartis
0
190
開発者フレンドリーで顧客も満足?Platformの秘密
algoartis
0
190
Dissecting and Reconstructing Ruby Syntactic Structures
ydah
3
2.1k
In geheimer Mission: AI Agents entwickeln
joergneumann
0
110
AI時代の開発者評価について
ayumuu
0
230
Featured
See All Featured
Code Review Best Practice
trishagee
67
18k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
12k
The Invisible Side of Design
smashingmag
299
50k
Fontdeck: Realign not Redesign
paulrobertlloyd
84
5.5k
Unsuck your backbone
ammeep
671
57k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
60k
Statistics for Hackers
jakevdp
798
220k
Code Reviewing Like a Champion
maltzj
523
40k
Designing Experiences People Love
moore
142
24k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
19
1.2k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
Visualization
eitanlees
146
16k
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)は、マルチスレッド ・プログラム実装上の問題