为什么 GCD 中的组没有 dispatch_group_sync 功能?

Why is there no dispatch_group_sync function for groups in GCD?

据说:

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.

由于这些块正在一个接一个地执行,因此从技术上讲,dispatch_group 的 GCD 函数应该是 dispatch_group_sync 而不是 dispatch_group_async.

提前感谢您的精彩解释。

因为这里async是相对于block提交的thread(Common main tread)而言的

你不需要同步组到那个线程,你只需要向那个线程添加代码,代码一个一个执行。

此外,还有调度组。

  • 如果将这些任务添加到串行队列(DISPATCH_QUEUE_SERIAL),则可以让这些任务一个接一个地执行。
  • 如果将这些任务添加到并发队列 (DISPATCH_QUEUE_CONCURRENT),也可以让这些任务并发执行。