Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
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
[SF Ruby Conf 2025] Rails X
palkan
0
490
ハイパーメディア駆動アプリケーションとIslandアーキテクチャ: htmxによるWebアプリケーション開発と動的UIの局所的適用
nowaki28
0
390
バックエンドエンジニアによる Amebaブログ K8s 基盤への CronJobの導入・運用経験
sunabig
0
140
配送計画の均等化機能を提供する取り組みについて(⽩⾦鉱業 Meetup Vol.21@六本⽊(数理最適化編))
izu_nori
0
140
無秩序からの脱却 / Emergence from chaos
nrslib
2
13k
UIデザインに役立つ 2025年の最新CSS / The Latest CSS for UI Design 2025
clockmaker
18
7.2k
テストやOSS開発に役立つSetup PHP Action
matsuo_atsushi
0
150
LLMで複雑な検索条件アセットから脱却する!! 生成的検索インタフェースの設計論
po3rin
2
640
Why Kotlin? 電子カルテを Kotlin で開発する理由 / Why Kotlin? at Henry
agatan
2
6.9k
Socio-Technical Evolution: Growing an Architecture and Its Organization for Fast Flow
cer
PRO
0
320
30分でDoctrineの仕組みと使い方を完全にマスターする / phpconkagawa 2025 Doctrine
ttskch
3
790
Tinkerbellから学ぶ、Podで DHCPをリッスンする手法
tomokon
0
120
Featured
See All Featured
Large-scale JavaScript Application Architecture
addyosmani
515
110k
Raft: Consensus for Rubyists
vanstee
141
7.2k
Making the Leap to Tech Lead
cromwellryan
135
9.7k
KATA
mclloyd
PRO
32
15k
Designing Experiences People Love
moore
143
24k
Producing Creativity
orderedlist
PRO
348
40k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.7k
Building Adaptive Systems
keathley
44
2.9k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.5k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
970
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
7.8k
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)は、マルチスレッド ・プログラム実装上の問題