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_applications.pdf
Search
ohayoukenchan
June 25, 2021
Programming
0
1.1k
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
7k
iOSDC2018_ohayou_kenchan.pdf
ohayoukenchan
4
3.8k
Other Decks in Programming
See All in Programming
[技育CAMPアカデミア]アイディアを形に!【超入門】スマホアプリ開発〜リリースまでの流れをご紹介
teamlab
PRO
0
340
Java 22 Overview
kishida
1
170
AWS Application Composerで始める、 サーバーレスなデータ基盤構築 / 20240406-jawsug-hokuriku-shinkansen
kasacchiful
1
250
⼤規模⾔語モデルの拡張(RAG)が 終わったかも知れない件について
nearme_tech
22
15k
StreamlitとTerraformでデータカタログを作った話
gussan0223
0
300
コードレビューで学ぶ!Kotlinオブジェクト指向デザインパターン
akkie76
2
180
受託開発でGitLab CI を活用していく
xiombatsg
1
270
Semantic search with Django and pgvector
pauloxnet
0
240
Folding Cheat Sheet #1
philipschwarz
PRO
0
210
#phpcon_odawara オープン・クローズドなテストフィクスチャを求めて / open closed test fixtures
77web
3
210
データアナリストが行うDatabricksを活用したETLの自動化事例
shinoa
0
250
大規模Reactアプリのリアーキテクチャ~8万行のTanStack Query移行の軌跡~
kj455
3
710
Featured
See All Featured
Bash Introduction
62gerente
604
210k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
6
990
Six Lessons from altMBA
skipperchong
20
3k
Learning to Love Humans: Emotional Interface Design
aarron
266
39k
How STYLIGHT went responsive
nonsquared
92
4.8k
Raft: Consensus for Rubyists
vanstee
132
6.2k
How to train your dragon (web standard)
notwaldorf
72
5.1k
Build your cross-platform service in a week with App Engine
jlugia
225
17k
Writing Fast Ruby
sferik
620
60k
No one is an island. Learnings from fostering a developers community.
thoeni
14
2.1k
ParisWeb 2013: Learning to Love: Crash Course in Emotional UX Design
dotmariusz
104
6.6k
Building Applications with DynamoDB
mza
88
5.6k
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)は、マルチスレッド ・プログラム実装上の問題