dispatch_group_leave crash in swift

笑着哭i 提交于 2019-12-13 12:58:41

问题


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_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.

Any ideas are most appreciated! Thanks!


回答1:


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




回答2:


In worst case if you want to chek the count of number of values enter You can do this by following patch

let count = self.groupExecuting.debugDescription.components(separatedBy: ",").filter({$0.contains("count")}).first!.components(separatedBy: CharacterSet.decimalDigits.inverted).filter({Int($0) != nil})


来源:https://stackoverflow.com/questions/30473158/dispatch-group-leave-crash-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!