Note that there are some explanatory texts on larger screens.

plurals
  1. POWorkaround on the threads limit in Grand Central Dispatch?
    primarykey
    data
    text
    <p>With <a href="http://developer.apple.com/library/ios/documentation/Performance/Reference/GCD_libdispatch_Ref/Reference/reference.html" rel="nofollow noreferrer">Grand Central Dispatch</a>, one can easily perform time consuming task on non-main thread, avoid blocking the main thead and keep the UI responsive. Simply by using <code>dispatch_async</code> and perform the task on a global concurrent queue.</p> <pre><code>dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ // code }); </code></pre> <p>However, something sounds too good to be true like this one usually have their downside. After we use this a lot in our iOS app project, recently we found that there's a 64 thread limit on it. Once we hit the limit, the app will freeze / hang. By pausing the app with Xcode, we can see that the main thread is held by <code>semaphore_wait_trap</code>.</p> <p>Googling on the web confirms that others are encountering this problem too but so far no solution found for this.</p> <blockquote> <p>Dispatch Thread Hard Limit Reached: 64 (too many dispatch threads blocked in synchronous operations)</p> </blockquote> <p><a href="https://stackoverflow.com/questions/14027824/gcd-dispatch-concurrent-queue-freeze-with-dispatch-thread-soft-limit-reached-6">Another stackoverflow question</a> confirms that this problem occur when using <code>dispatch_sync</code> and <code>dispatch_barrier_async</code> too.</p> <p><strong>Question:</strong><br> As the Grand Central Dispatch have a 64 threads limit, is there any workaround for this?</p> <p>Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload