How to handle Race Condition Read Write in Swift?
问题 I have got a concurrent queue with dispatch barrier from Raywenderlich post Example private let concurrentPhotoQueue = DispatchQueue(label: "com.raywenderlich.GooglyPuff.photoQueue", attributes: .concurrent) Where write operations is done in func addPhoto(_ photo: Photo) { concurrentPhotoQueue.async(flags: .barrier) { [weak self] in // 1 guard let self = self else { return } // 2 self.unsafePhotos.append(photo) // 3 DispatchQueue.main.async { [weak self] in self?.postContentAddedNotification(