0
在运行ThreadSanitizer在我的应用我有一个数据种族问题而并发下载的文件,该如何解决呢斯威夫特:运行时:线程问题:数据种族MyApp.DownloadManager.progress.setter:Swift.Float在0x7b1400209130
这里是断点代码:
func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didWriteData bytesWritten:
Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64) {
if let downloadUrl = downloadTask.originalRequest?.url?.absoluteString,
let download = activeDownloads[downloadUrl] {
//break point indicate here:-
download.progress = Float(totalBytesWritten)/Float(totalBytesExpectedToWrite)
let totalSize = ByteCountFormatter.string(fromByteCount: totalBytesExpectedToWrite, countStyle: ByteCountFormatter.CountStyle.binary)
DispatchQueue.main.async(execute: {
if let trackIndex = self.trackIndexForDownloadTask(downloadTask), let trackCell = self.tableView.cellForRow(at: IndexPath(row: trackIndex, section: 0)) as? AmbientCell {
trackCell.progressView.progress = Double(download.progress)
if download.progress == 1.0 {
trackCell.progressView.isHidden = true
trackCell.downloadCompleted.isHidden = false
}
}
})
}
}
已满警告日志 - ThreadSanitizer: data race