Apple said "If you use Value type, you can safely pass copies of values across threads without synchronization.". But I saw concurrency crash at variance with the apple guide recently.
I saw https://developer.apple.com/swift/blog/?id=10 and Apple's guide that said "value type is safe in multithreads" so I thought "Value type is atomic!" but recently I saw concurrency crash in code below.
class ClassB: NSObject {
func readSomeValue() {
print(classA.someValue)
}
let classA = ClassA()
}
class ClassA: NSObject {
private(set) var someValue: StructA? {
didSet{
if oldValue != self.someValue { self.someFunction(self.someValue) }
}
}
private func modifySomeValue(_ newValue: StructA) {
self.someValue = newValue
}
}
struct StructA {
var a: Double
var b: String?
}
concurrency crash is occured when execute readSomeValue() in thread1 and execute modifySomeValue() in thread2. Why does concurrency crash happen? Is Value type not safe in multithreads?