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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
ohayoukenchan
June 25, 2021
Programming
1.4k
0
Share
protect_mutable_state_in_concurrent_Swift_applications.pdf
ohayoukenchan
June 25, 2021
More Decks by ohayoukenchan
See All by ohayoukenchan
iOSDC2021 知られざる課金ステータス
ohayoukenchan
1
8.3k
iOSDC2018_ohayou_kenchan.pdf
ohayoukenchan
4
4.3k
Other Decks in Programming
See All in Programming
RSAが破られる前に知っておきたい 耐量子計算機暗号(PQC)入門 / Intro to PQC: Preparing for the Post-RSA Era
mackey0225
3
110
おれのAgentic Coding 2026/03
tsukasagr
1
120
Symfonyの特性(設計思想)を手軽に活かす特性(trait)
ickx
0
110
へんな働き方
yusukebe
6
2.9k
年間50登壇、単著出版、雑誌寄稿、Podcast出演、YouTube、CM、カンファレンス主催……全部やってみたので面白さ等を比較してみよう / I’ve tried them all, so let’s compare how interesting they are.
nrslib
4
640
Codex の「自走力」を高める
yorifuji
0
1.3k
コードレビューをしない選択 #でぃーぷらすトウキョウ
kajitack
3
1.2k
Tamach-sre-3_ANDPAD-shimaison93
mane12yurks38
0
240
見せてもらおうか、 OpenSearchの性能とやらを!
shunta27
1
170
AI Assistants for YourAngular Solutions @Angular Graz, March 2026
manfredsteyer
PRO
0
140
メッセージングを利用して時間的結合を分離しよう #phperkaigi
kajitack
3
530
最初からAWS CDKで技術検証してもいいんじゃない?
akihisaikeda
4
180
Featured
See All Featured
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
290
YesSQL, Process and Tooling at Scale
rocio
174
15k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
500
Paper Plane
katiecoart
PRO
1
48k
Exploring anti-patterns in Rails
aemeredith
3
300
30 Presentation Tips
portentint
PRO
1
270
Accessibility Awareness
sabderemane
0
89
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
61
43k
Testing 201, or: Great Expectations
jmmastey
46
8.1k
VelocityConf: Rendering Performance Case Studies
addyosmani
333
25k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
110
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
340
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)は、マルチスレッド ・プログラム実装上の問題