1
votes

I have couple of questions:

  1. When any custom dispatch queue (serial or concurrent) is created on which thread do they execute tasks.

  2. 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.

  1. What happens if dispatch_suspend() or dispatch_resume() is called on global queues?
2
u can refer this for third question stackoverflow.com/questions/20332936/…Meenakshi Borade

2 Answers

2
votes

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().

0
votes
  1. 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.

  1. 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.

  1. What happens if dispatch_suspend() or dispatch_resume() is called on global queue?

As the documentation says, they have no effect:

Calls to the suspend(), resume(), and dispatch_set_context(_:_:) functions have no effect on the returned queues.

You can’t use barriers on global queues, either.