Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a high priority serial dispatch queue with GCD

Tags:

How can I create a custom serial queue that runs at high priority?

Right now I'm using myQueue = dispatch_queue_create("com.MyApp.MyQueue", NULL); but this doesn't seem to allow for setting a priority?

like image 771
Mark Wheeler Avatar asked Jul 17 '13 03:07

Mark Wheeler


People also ask

What is GCD and dispatch queue?

First off, the dominating phrase in GCD is the dispatch queue. A queue is actually a block of code that can be executed synchronously or asynchronously, either on the main or on a background thread. Dispatch queues are FIFO queues to which your application can submit tasks in the form of block objects.

What is serial queue in GCD?

Async means execute next line do not wait until the block executes which results non blocking main thread & main queue. Since its serial queue, all are executed in the order they are added to serial queue. Tasks executed serially are always executed one at a time by the single thread associated with the Queue.

What is GCD in swift5?

Grand Central Dispatch (GCD) is a low-level API for managing concurrent operations. It can help improve your app's responsiveness by deferring computationally expensive tasks to the background. It's an easier concurrency model to work with than locks and threads.

What is the GCD in iOS?

Overview. Dispatch, also known as Grand Central Dispatch (GCD), contains language features, runtime libraries, and system enhancements that provide systemic, comprehensive improvements to the support for concurrent code execution on multicore hardware in macOS, iOS, watchOS, and tvOS.


1 Answers

Create a serial queue, then use dispatch_set_target_queue() to set its target queue to the high priority queue.

Here's how:

dispatch_set_target_queue(myQueue, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)); 

Now myQueue should run serially with high priority. Here's another SO answer if you want to know more.

like image 91
Catfish_Man Avatar answered Sep 23 '22 16:09

Catfish_Man