Swift-线程竞争的线程竞赛
我在项目上正在运行线程速度,并且结果非常不一致。我的设置如下:
- 围绕Urlsession的包装器,该urlsession报告了后退任务及其状态。我通过:
actor MyMonitor {
func getTasks() async -> [String: URLSessionTask] {
await mySession.allTasks.reduce(into: [String: URLSessionTask]()) { newMap, element in
if let taskDescription = element.taskDescription {
newMap[taskDescription] = element
}
}
}
}
对于我的单元测试,我有一个URLProtocol来嘲笑实际的工作请求。但是,似乎当我调用getTasks
函数时,我会获得数据竞赛。 (尽管不一致)
TSAN工具指出种族在上述片段中:
线程问题:(2)中的数据竞赛等待恢复部分功能 myproject.mymonitor.getTasks()async-> swift.dictionary< swift.string, __c.nsurlsessionTask>请致电0x7B6000021400
这是一个假阳性,因为我没有控制Ove urlsession的螺纹?任何帮助将不胜感激。
I am running ThreadSanitizer on my project and I am getting some very inconsistent results. My setup is as follows:
- A wrapper around a URLSession which reports back tasks and their status. I get the tasks via:
actor MyMonitor {
func getTasks() async -> [String: URLSessionTask] {
await mySession.allTasks.reduce(into: [String: URLSessionTask]()) { newMap, element in
if let taskDescription = element.taskDescription {
newMap[taskDescription] = element
}
}
}
}
For my unit tests, I have a URLProtocol to mock an actual working request. However, it seems when I call the getTasks
function, I get a data race. (albeit inconsistent)
The TSan tool states the race is in the above snippet:
Threading Issues: Data race in (2) await resume partial function for
MyProject.MyMonitor.getTasks() async -> Swift.Dictionary<Swift.String,
__C.NSURLSessionTask> at 0x7b6000021400
Is this a false positive, because I do not have control ove URLSession's threading? Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论