Vivek Deore
Vivek Deore

Reputation: 71

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.

Upvotes: 3

Views: 765

Answers (1)

Leo
Leo

Reputation: 24714

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

Upvotes: 4

Related Questions