切换到 Xcode 14 beta 后,我收到此错误:QOS_CLASS_USER_INITIATED waiting on a lower QoS thread running at QOS_CLASS_DEFAULT

Vah*_*hid 38 xcode multithreading ios swift priority-inversion

我的应用程序运行良好,我在 Xcode 13.4 上没有收到此错误,是 Xcode 14 beta 错误还是我做了一些糟糕的线程处理?!

Thread running at QOS_CLASS_USER_INITIATED waiting on a lower QoS thread running at QOS_CLASS_DEFAULT. Investigate ways to avoid priority inversions

QOS_CLASS_USER_INITIATED 正在等待以 QOS_CLASS_DEFAULT 运行的较低 QoS 线程。

我不明白这个问题,所以我也添加了我的堆栈日志:

_TtGC7SwiftUI14_UIHostingViewVVS_P10$1dc8d4d8821BridgedNavigationView8RootView_ implements focusItemsInRect: - caching for linear focus movement is limited as long as this view is on screen.
2022-06-07 18:53:41.412342+0430 MyApp[916:25641] [UIFocus] _TtCC7SwiftUI17HostingScrollView22PlatformGroupContainer implements focusItemsInRect: - caching for linear focus movement is limited as long as this view is on screen.
Thread Performance Checker: Thread running at QOS_CLASS_USER_INITIATED waiting on a lower QoS thread running at QOS_CLASS_DEFAULT. Investigate ways to avoid priority inversionsPID: 916, TID: 25815
Backtrace
=================================================================
3   MyApp                                 0x0000000102c7665c -[_FSRRunLoopThread runLoop] + 44
4   MyApp                                 0x0000000102c763a8 __45+[NSRunLoop(FSRWebSocket) FSR_networkRunLoop]_block_invoke + 124
5   libdispatch.dylib                   0x00000001054318fc _dispatch_client_callout + 16
6   libdispatch.dylib                   0x0000000105433240 _dispatch_once_callout + 80
7   MyApp                                 0x0000000102c76304 +[NSRunLoop(FSRWebSocket) FSR_networkRunLoop] + 84
8   MyApp                                 0x0000000102c6ff30 -[FSRWebSocket _connect] + 68
9   MyApp                                 0x0000000102c6ed60 -[FSRWebSocket open] + 216
10  MyApp                                 0x0000000102c4ebdc -[FWebSocketConnection open] + 248
11  MyApp                                 0x0000000102c4d3c4 -[FConnection open] + 112
12  MyApp                                 0x0000000102bf1404 -[FPersistentConnection openNetworkConnectionWithContext:] + 588
13  MyApp                                 0x0000000102bf1078 __45-[FPersistentConnection tryScheduleReconnect]_block_invoke_2 + 332
14  MyApp                                 0x0000000102c3d0fc -[FIRDatabaseConnectionContextProvider fetchContextForcingRefresh:withCallback:] + 264
15  MyApp                                 0x0000000102bf0f0c __45-[FPersistentConnection tryScheduleReconnect]_block_invoke + 460
16  MyApp                                 0x0000000102c1c0d8 -[FIRRetryHelperTask execute] + 92
17  MyApp                                 0x0000000102c1c6dc __24-[FIRRetryHelper retry:]_block_invoke + 84
18  libdispatch.dylib                   0x00000001054300c4 _dispatch_call_block_and_release + 24
19  libdispatch.dylib                   0x00000001054318fc _dispatch_client_callout + 16
20  libdispatch.dylib                   0x0000000105438a58 _dispatch_lane_serial_drain + 688
21  libdispatch.dylib                   0x00000001054396d0 _dispatch_lane_invoke + 424
22  libdispatch.dylib                   0x0000000105445150 _dispatch_workloop_worker_thread + 696
23  libsystem_pthread.dylib             0x000000023db94ddc _pthread_wqthread + 284
24  libsystem_pthread.dylib             0x000000023db94908 start_wqthread + 8
Run Code Online (Sandbox Code Playgroud)

ham*_*ail 11

由于代码中的优先级反转,您收到此消息。更多详细信息请参见:https://developer.apple.com/documentation/xcode/diagnosing-performance-issues-early

更具体地说,您使用的dispatch_group_waitwhich 不提供优先级反转避免;所以你的等待线程很容易发生反转。看来这就是这里发生的事情。

  • @SheikhWa​​habMahmood 实际上代码之前就存在问题,只是 Xcode 没有检测到。这是 Xcode 14 中的新检测。 (8认同)