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
8.1k
iOSDC2018_ohayou_kenchan.pdf
ohayoukenchan
4
4.2k
Other Decks in Programming
See All in Programming
ボトムアップの生成AI活用を推進する社内AIエージェント開発
aku11i
0
1.4k
スキーマ駆動で、Zod OpenAPI Honoによる、API開発するために、Hono Takibiというライブラリを作っている
nakita628
0
330
Towards Transactional Buffering of CDC Events @ Flink Forward 2025 Barcelona Spain
hpgrahsl
0
120
外接に惑わされない自システムの処理時間SLIをOpenTelemetryで実現した話
kotaro7750
0
150
CSC509 Lecture 07
javiergs
PRO
0
250
Developer Joy - The New Paradigm
hollycummins
1
400
iOSでSVG画像を扱う
kishikawakatsumi
0
180
SidekiqでAIに商品説明を生成させてみた
akinko_0915
0
110
業務でAIを使いたい話
hnw
0
220
TransformerからMCPまで(現代AIを理解するための羅針盤)
mickey_kubo
7
5.9k
GitHub Copilotを使いこなせ!/mastering_github_copilot!
kotakageyama
2
710
CSC509 Lecture 09
javiergs
PRO
0
280
Featured
See All Featured
Product Roadmaps are Hard
iamctodd
PRO
55
11k
Unsuck your backbone
ammeep
671
58k
Side Projects
sachag
455
43k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
116
20k
Build your cross-platform service in a week with App Engine
jlugia
234
18k
Designing for Performance
lara
610
69k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
34
2.3k
What's in a price? How to price your products and services
michaelherold
246
12k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
Balancing Empowerment & Direction
lara
5
710
How STYLIGHT went responsive
nonsquared
100
5.9k
jQuery: Nuts, Bolts and Bling
dougneiner
65
7.9k
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)は、マルチスレッド ・プログラム実装上の問題