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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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.4k
Other Decks in Programming
See All in Programming
Inside Stream API
skrb
1
600
自動レビューエンジンの実装と運用 ~レビューのない世界へ~
kurukuru1999
2
310
oxlintはeslint/typescript-eslintを置き換えられるのか
shomafujita
2
310
正しくソフトウェアを作る、前提を疑うための認知の視点 / doubt-premise
minodriven
17
5.3k
Stage 3 Decorators でできること / できないこと / TSKaigi 2026
susisu
1
1.5k
TAKTでAI駆動開発の品質を設計する
j5ik2o
4
270
CLIであることを活かしたGitHub Copilot CLI活用術 / GitHub Copilot CLI Pro Tips & Tricks
nao_mk2
1
1.2k
Technical Debt: Understanding it Rightly, Engaging it Rightly #LaravelLiveJP
shogogg
0
190
肥大化するレガシーコードに立ち向かうためのインターフェース分離と依存の逆転 / JJUG CCC 2026 Spring
hirokunimaeta
0
450
Transactional Change Stream Processing With Debezium and Apache Flink
gunnarmorling
1
160
気づいたらRubyで100作品 ー クリエイティブコーディングが生活の一部になるまで / 100 Ruby Sketches Later: How Creative Coding Became Part of My Life
chobishiba
3
530
Old Dog, New Tricks: The Java 25 Reinvention - JNation
bazlur_rahman
0
140
Featured
See All Featured
エンジニアに許された特別な時間の終わり
watany
107
240k
RailsConf 2023
tenderlove
30
1.5k
Agile that works and the tools we love
rasmusluckow
331
21k
Claude Code のすすめ
schroneko
67
220k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.9k
Between Models and Reality
mayunak
4
320
The Cost Of JavaScript in 2023
addyosmani
55
10k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
200
Into the Great Unknown - MozCon
thekraken
41
2.5k
Building Applications with DynamoDB
mza
96
7.1k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
200
GitHub's CSS Performance
jonrohan
1033
470k
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)は、マルチスレッド ・プログラム実装上の問題