Dispatch_group_leave crash in fast

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

0 libdispatch.dylib 0x0000000197a85a9c dispatch_group_leave + 48 

dispatch_group_leave is called in full closure, which is called as follows:

  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 send to the background thread, run HKStatisticsCollectionQuery, and then call the closure of the function parameter, called full. Inside complete, dispatch_group_leave is called and a crash occurs.

Any ideas are most appreciated! Thanks!

+12
source share
2 answers

If the dispatch_group_leave call is not balanced with dispatch_group_enter , then it may fail.

+19
source

In the worst case, if you want to check the number of values ​​entered, you can do this by following the patch

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

All Articles