Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

macos - Consistent Dispatch queue: com.apple.root.default-qos.overcommit crash

Anyone had experience diagnosing these crashes? I have a single user getting them consistently, and though I found an iOS related post, my app is not crashing on the same type of operation...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Reason:

in iOS / tvOS there are queues / threads, each thread has its own type or priority also known as a "quality of service" or for short "QOS", which means the level of urgency that the cpu should handle this thread, the possibilities are:

  • QOS_CLASS_DEFAULT
  • QOS_CLASS_USER_INITIATED
  • QOS_CLASS_UTILITY
  • QOS_CLASS_BACKGROUND
  • QOS_CLASS_UNSPECIFIED
  • QOS_CLASS_USER_INTERACTIVE

once you run too many tasks at the same time in the same queue, then the OS notifies you that it cannot perform all this tasks at the same time in the same priority (there is a limit to the size of the stack for each queue), there for it says "OverCommit", which means you have over committed the queue (in your case the "Default-QOS" queue) and it exits since it cannot receive more tasks at this time and execute them at the fashion you want.

solution:

what you should do is first find the "dispatch_async" command that causes this crash, then use one of the other queues (it means expecting slower response then expected for that task),

usually developer don't think about it and simply use main queue which is the default priority / queue like this:

dispatch_async(dispatch_get_main_queue()) {
    // some task to perform
    print("This is my task")
}

in order to fix this (if the app notifies you that you have overcommitted the main queue) is to change it to one of the other queues like this:

let qualityOfServiceClass = QOS_CLASS_BACKGROUND
let backgroundQueue = dispatch_get_global_queue(qualityOfServiceClass, 0)
dispatch_async(backgroundQueue, {
    // some task to perform
    print("This is my task")
})

if you do not require a background (or parallel) execution, you can even ignore the dispatch_async command altogether and simply execute you commands like this:

// some task to perform
print("This is my task")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...