dispatch_group_leave在swift中崩溃

时间:2021-08-27 16:03:06

This happens very rarely. Here is the last line of the stack trace:

这很少发生。这是堆栈跟踪的最后一行:

0  libdispatch.dylib              0x0000000197a85a9c dispatch_group_leave + 48

dispatch_group_leave is called in a complete closure which is invoked like this:

dispatch_group_leave在一个完整的闭包中调用,它被调用如下:

  dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
                { () -> Void in
                    let query = HKStatisticsCollectionQuery(quantityType: quantityType,
                        quantitySamplePredicate: nil,
                        options: statisticOptions,
                        anchorDate: anchorDate,
                        intervalComponents: interval)
                    query.initialResultsHandler = {

                        complete()

So we dispatch to a background thread, run a HKStatisticsCollectionQuery, and then call a function parameter closure called complete. Inside complete is where the dispatch_group_leave is called and the crash happens.

所以我们调度到后台线程,运行HKStatisticsCollectionQuery,然后调用一个名为complete的函数参数闭包。内部完成是调用dispatch_group_leave并发生崩溃的地方。

Any ideas are most appreciated! Thanks!

任何想法都非常感谢!谢谢!

1 个解决方案

#1


13  

If dispatch_group_leave call isn't balanced with dispatch_group_enter then crash may happen.

如果dispatch_group_leave调用与dispatch_group_enter不平衡,则可能发生崩溃。

#1


13  

If dispatch_group_leave call isn't balanced with dispatch_group_enter then crash may happen.

如果dispatch_group_leave调用与dispatch_group_enter不平衡,则可能发生崩溃。