Isola&on Domainのカテゴリー
all func&on and variable declara&ons have a well-defined sta&c
isola&on domain. These domains will always fall into one of three
categories:
1. Non-isolated
2. Isolated to an actor value
3. Isolated to a global actor
2
"Migra)ng to Swi/ 6" h2ps://www.swi/.org/migra)on/documenta)on/swi/-6-concurrency-migra)on-guide/
dataracesafety#Isola)on-Domains
Global ActorとIsola-on Domain
@MainActor
final class FooViewModel {
var value: Int = 42
}
Slide 44
Slide 44 text
Global ActorとIsola-on Domain
@MainActor
final class FooViewModel {
var value: Int = 42
}
// 暗黙的に@MainActor
final class FooViewController: UIViewController {
let viewModel: FooViewModel = .init()
func buttonPressed() {
print(viewModel.value) // 同期
}
}
古い設計で解体するのが困難なミュータブルクラス
final class OldFatService {
var value: Int
// ...
}
Slide 112
Slide 112 text
ミュータブルなのでSendable準拠できない
final class OldFatService: Sendable { //
var value: Int
// ...
}
Slide 113
Slide 113 text
Mutexで可変状態を保護する
final class OldFatService: Sendable { //
var value: Int {
get { _value.withLock { $0 } }
set { _value.withLock { $0 = newValue } }
}
private let _value: Mutex
}
// ...
Slide 114
Slide 114 text
Mutexで可変状態を保護する
import Synchronization
final class OldFatService: Sendable { //
var value: Int {
get { _value.withLock { $0 } }
set { _value.withLock { $0 = newValue } }
}
private let _value: Mutex
}
// ...
Slide 115
Slide 115 text
OSAllocatedUnfairLock (iOS 16, 17)
import os
final class OldFatService: Sendable { //
var value: Int {
get { _value.withLock { $0 } }
set { _value.withLock { $0 = newValue } }
}
private let _value: OSAllocatedUnfairLock
}
// ...
What is the difference between
isola2on domain and concurrency domain?
I'm leaning toward standardizing on "concurrency domain" and
upda7ng the migra7on guide to use that term instead of "isola7on
1
domain"
— Holly Borla (Mar 2, 2025)
1
h$ps://github.com/swi3lang/swi3-migra9on-guide/issues/130#issuecomment-2692364765