Thanks @DTS Engineer . This is very helpful.
First off, as background, Dispatch's "main queue" is NOT in fact a "dispatch queue"/dispatch_queue_main_t. Our interface frameworks (UIKit/AppKit) both have the concept of the "main thread", which is both the first thread created and is there those thread use a RunLoop to receive events. The "dispatch main queue" was created to provide a convenient way to send messages to that special thread. In an that uses an main thread runloop, dispatching to the main thread does the same thing as "performSelectorOnMainThread".
So, even in case of non interaction apps - (1) In gui session, our apps use NSApplicationMain() (2) In non-gui session, like the case of daemons, we use CFRunLoopRun() - so it should be safe to dispatch work on main thread?
[Main Dispatch Queue] [Link] Because the main queue doesn't behave entirely like a regular serial queue, it may have unwanted side-effects when used in processes that are not UI apps (daemons). For such processes, the main queue should be avoided.
This guideline is for non interaction apps that don't get into a RunLoop on the main thread?
Putting that in more concrete terms, the conceptual idea here was/is that dispatch queues feed work "into the system" while the global queues are responsible for managing and scheduling work on to the entire thread pool.
The design mistake here was that allowing work to be directly submitted to the global queues unnecessarily confused this API division and created a bug opportunity that did not really need to exist.
Though the intent and problem created is now clear from above response. Can you now explain - how that has now been remedied or attempted to improve using over-commiting and non-overcommiting queues for global concurrent queues?
I am sharing my understanding from what I have learnt from the responses:
GCD manages a thread pool per process
GCD custom queues can have other GCD custom queues as target but eventually the leaf custom queue targets one of the global queues.
These GCD custom queues (whether serial or concurrent) are there to only feed work "into the system"
The actual work happens in the global queues - responsible for managing and scheduling work on to the entire thread pool per process.
This merger of work across queues in hierarchy and the scheduling of work ensures that the execution semantics are preserved for a queue (serial - one block at a time and concurrent - multiple blocks at a time)
Please let me know if the understanding is correct.