The XCODE TSAN thread analyser is throwing up a threading issue:
Data race in generic specialization <Foundation.UUID> of Swift._NativeSet.insertNew(_: __owned τ_0_0, at: Swift._HashTable.Bucket, isUnique: Swift.Bool) -> () at 0x10a16b300
This only occurs in a release build, and its Data race in generic specialization
that has my attention.
It pin-points the addID
function. But I cannot see the issue. Here is the relevant code snippet:
final class IDBox {
let syncQueue = DispatchQueue(label: "IDBox\(UUID().uuidString)", attributes: .concurrent)
private var _box: Set<UUID>
init() {
self._box = []
}
var box: Set<UUID> {
syncQueue.sync {
self._box
}
}
func addID(_ id: UUID) {
syncQueue.async(flags: .barrier) {
self._box.insert(id)
}
}
}