Hi,
Overview
I have a variable onGoingFetchCount
that I am accessing in the main thread and in the background thread.
Problem:
TSAN didn't catch this when the code was executed.
Question:
Am I missing something ?
Note:
- I have checked the Thread Sanitizer checkbox (Edit Scheme > Run > Diagnostics > Thread Sanitizer checkbox)
- Swift 5.2
- Xcode - 11.4 (11E146)
Code:
class Test {
var onGoingFetchCount = 0
let queue = OperationQueue()
func run() {
fetch { value in
print("value = \(value)")
}
}
func fetch(completion: @escaping (String) -> ()) {
onGoingFetchCount += 1 //Main thread
let operation = BlockOperation {
self.onGoingFetchCount -= 1 //Background thread
completion("testing")
}
queue.addOperation(operation)
}
}
let test = Test()
test.run()