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
「兵法」から見る質とスピード
ickx
0
260
Using AI Tools Around Software Development
inouehi
0
1.2k
UPDATEがシステムを複雑にする? イミュータブルデータモデルのすすめ
shimomura
1
530
Parallel::Pipesの紹介
skaji
2
910
セキュリティマネジャー廃止とクラウドネイティブ型サンドボックス活用
kazumura
1
170
Datadog RUM 本番導入までの道
shinter61
1
260
Development of an App for Intuitive AI Learning - Blockly Summit 2025
teba_eleven
0
110
単体テストの始め方/作り方
toms74209200
0
430
Cloudflare Realtime と Workers でつくるサーバーレス WebRTC
nekoya3
0
400
iOSアプリ開発で 関数型プログラミングを実現する The Composable Architectureの紹介
yimajo
2
210
Spring gRPC で始める gRPC 入門 / Introduction to gRPC with Spring gRPC
mackey0225
2
490
ワンバイナリWebサービスのススメ
mackee
10
7.7k
Featured
See All Featured
Faster Mobile Websites
deanohume
307
31k
The Invisible Side of Design
smashingmag
299
51k
KATA
mclloyd
29
14k
Being A Developer After 40
akosma
90
590k
We Have a Design System, Now What?
morganepeng
52
7.6k
Building a Modern Day E-commerce SEO Strategy
aleyda
41
7.3k
Measuring & Analyzing Core Web Vitals
bluesmoon
7
480
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
StorybookのUI Testing Handbookを読んだ
zakiyama
30
5.8k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
657
60k
For a Future-Friendly Web
brad_frost
179
9.8k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.4k
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)は、マルチスレッド ・プログラム実装上の問題