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
生成AIコーディングとの向き合い方、AIと共創するという考え方 / How to deal with generative AI coding and the concept of co-creating with AI
seike460
PRO
1
330
型付きアクターモデルがもたらす分散シミュレーションの未来
piyo7
0
810
Composerが「依存解決」のためにどんな工夫をしているか #phpcon
o0h
PRO
1
210
Webの外へ飛び出せ NativePHPが切り拓くPHPの未来
takuyakatsusa
2
320
DroidKnights 2025 - 다양한 스크롤 뷰에서의 영상 재생
gaeun5744
3
310
Deep Dive into ~/.claude/projects
hiragram
7
1.2k
Claude Codeの使い方
ttnyt8701
1
130
たった 1 枚の PHP ファイルで実装する MCP サーバ / MCP Server with Vanilla PHP
okashoi
1
170
エンジニア向け採用ピッチ資料
inusan
0
160
Team topologies and the microservice architecture: a synergistic relationship
cer
PRO
0
1k
Julia という言語について (FP in Julia « SIDE: F ») for 関数型まつり2025
antimon2
3
980
明示と暗黙 ー PHPとGoの インターフェイスの違いを知る
shimabox
2
280
Featured
See All Featured
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
357
30k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
Code Review Best Practice
trishagee
68
18k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
15
1.5k
Bash Introduction
62gerente
614
210k
A designer walks into a library…
pauljervisheath
206
24k
Documentation Writing (for coders)
carmenintech
71
4.9k
Making the Leap to Tech Lead
cromwellryan
134
9.3k
Building Adaptive Systems
keathley
43
2.6k
[RailsConf 2023] Rails as a piece of cake
palkan
55
5.6k
Build The Right Thing And Hit Your Dates
maggiecrowley
36
2.8k
Building a Scalable Design System with Sketch
lauravandoore
462
33k
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)は、マルチスレッド ・プログラム実装上の問題