【发布时间】:2017-10-09 06:17:47
【问题描述】:
在我的应用程序中运行 ThreadSanitizer 时,我在并发下载文件时遇到了数据争用问题,如何解决它
这里是断点代码:
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
【问题讨论】:
标签: ios swift multithreading xcode9