Reputation: 7233
I have couple of questions:
When any custom dispatch queue (serial or concurrent) is created on which thread do they execute tasks.
I am a bit confused by below text from GCD documentation here:
In addition to any custom queues you create, the system automatically creates a serial queue and binds it to your application’s main thread. For more information about getting the queue for the main thread, see Getting Common Queues at Runtime.
Upvotes: 1
Views: 476
Reputation: 438212
- When any custom dispatch queue (serial or concurrent) is created on which thread do they execute tasks.
GCD creates “worker threads”, places them in a “pool”, and it draws upon that pool as threads are needed. Bottom line, GCD takes care of all of the thread-related stuff for you and you need not worry about that.
- I am a bit confused by below text from GCD documentation here:
In addition to any custom queues you create, the system automatically creates a serial queue and binds it to your application’s main thread. For more information about getting the queue for the main thread, see Getting Common Queues at Runtime.
It’s just saying that GCD creates the main
queue for you, binding it to the app’s main thread. Since everything we do in GCD is with queues, we need a queue bound to the main thread so that we can use standard GCD patterns to dispatch to it.
- What happens if
dispatch_suspend()
ordispatch_resume()
is called on global queue?
As the documentation says, they have no effect:
Calls to the
suspend()
,resume()
, anddispatch_set_context(_:_:)
functions have no effect on the returned queues.
You can’t use barriers on global queues, either.
Upvotes: 0
Reputation: 299595
You should break these kinds of things into separate questions. This kind of mega-question makes it hard on future searchers.
When any custom dispatch queue (serial or concurrent) is created on which thread do they execute tasks.
This is not defined. You cannot make any assumptions about which underlying thread will be used. From block to block on the same queue it may change. It may even be the dispatching thread in some cases.
The queue on the application's main thread is the main dispatch queue. You can access it with dispatch_get_main_queue()
.
The global queues ignore dispatch_suspend()
and dispatch_resume()
. This is documented in the discussion of dispatch_get_global_queue()
.
Upvotes: 2