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.2k
iOSDC2018_ohayou_kenchan.pdf
ohayoukenchan
4
4.3k
Other Decks in Programming
See All in Programming
チームをチームにするEM
hitode909
0
420
Pythonではじめるオープンデータ分析〜書籍の紹介と書籍で紹介しきれなかった事例の紹介〜
welliving
3
680
認証・認可の基本を学ぼう後編
kouyuume
0
260
ZJIT: The Ruby 4 JIT Compiler / Ruby Release 30th Anniversary Party
k0kubun
1
300
AtCoder Conference 2025「LLM時代のAHC」
imjk
2
610
生成AIを利用するだけでなく、投資できる組織へ
pospome
2
430
re:Invent 2025 トレンドからみる製品開発への AI Agent 活用
yoskoh
0
550
AI Agent Tool のためのバックエンドアーキテクチャを考える #encraft
izumin5210
5
1.5k
Cap'n Webについて
yusukebe
0
160
LLMで複雑な検索条件アセットから脱却する!! 生成的検索インタフェースの設計論
po3rin
4
1k
2年のAppleウォレットパス開発の振り返り
muno92
PRO
0
130
[AtCoder Conference 2025] LLMを使った業務AHCの上⼿な解き⽅
terryu16
6
970
Featured
See All Featured
Raft: Consensus for Rubyists
vanstee
141
7.3k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
0
110
Paper Plane (Part 1)
katiecoart
PRO
0
2.5k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.1k
Git: the NoSQL Database
bkeepers
PRO
432
66k
Information Architects: The Missing Link in Design Systems
soysaucechin
0
720
How to build a perfect <img>
jonoalderson
0
4.8k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
140
Applied NLP in the Age of Generative AI
inesmontani
PRO
3
2k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
55k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
0
34
Ethics towards AI in product and experience design
skipperchong
1
150
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)は、マルチスレッド ・プログラム実装上の問題