Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is there no dispatch_group_sync function for groups in GCD?

It is said that :

GCD lets us create groups, which allow you to place your tasks in one place, run all of them, and get a notification at the end from GCD. Those group blocks of code together ensure that all of them get executed by GCD one by one, as dependencies of one another.

As those blocks are getting executed one by one, then technically GCD function for dispatch_group should be dispatch_group_sync not dispatch_group_async.

Thanks in advance for great explanation.

like image 242
Vivek Deore Avatar asked Nov 19 '25 22:11

Vivek Deore


1 Answers

Because here async is relative to the thread(Common main tread) that the block is submitted.

You do not need to sync groups to that thread,you just add code to that thread,code is executed one by one.

Besides,with dispatch group.

  • You can let tasks execute one by one if you add those tasks to a serial queue(DISPATCH_QUEUE_SERIAL).
  • You can also let tasks execute concurrent if you add those tasks to a concurrent queue(DISPATCH_QUEUE_CONCURRENT).
like image 114
Leo Avatar answered Nov 21 '25 12:11

Leo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!