How to get the list of tasks in the GCD queue?

I get the main queue in the GCD, as shown below, and add various tasks from different classes in my applications.

dispatch_queue_t queue = dispatch_get_global_queue ( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); 

Now I want to know how many of my tasks remain in the main GCD queue.

Is there a way to get the list of tasks in the GCD queue?

thanks

+4
source share
2 answers

This is really not a GCD paradigm. For example, if you want to track a specific group of operations, you can create a dispatch group and register to be notified when this is done, as in this example.

 dispatch_group_t taskGroup = dispatch_group_create(); dispatch_queue_t queue = //Get whatever queue you want here dispatch_group_async(taskGroup, queue, ^ { [object doSomething]; }); dispatch_group_async(taskGroup, queue, ^ { [object doMoreStuff]; }); dispatch_group_async(taskGroup, queue, ^ { [object doEvenMoreStuff]; }); dispatch_group_notify(taskGroup, queue, ^{ [object workDone]; }); dispatch_release(taskGroup); 
+4
source

This is usually done with dispatch groups, not queues. You can assign tasks to a group using dispatch_group_async() , or you can manually mark things in a group using dispatch_group_enter() and dispatch_group_leave() . Then you can check if there is anything in the group using either dispatch_group_notify() or dispatch_group_wait() .

+2
source

Source: https://habr.com/ru/post/1401094/


All Articles