分派组:将在一个组的上下文通过dispatch_ground_async()函数异步分派所有程序块设置为松散的,以尽可能快的执行,如果可能,将它们分发给多个线程来同时执行。也可以使用dispatch_ground_notify指定一个额外的程序块,该程序块在组中的所有程序块即将运行完成时执行。
eg:
dispatch_async(dispatch_get_global_queue(0,0), ^{
__block NSString *first;
__block NSString *second;
dispatch_ground_t ground = dispatch_ground_create();
dispatch_ground_async(ground, dispatch_get_global_queue(0,0), ^{\
first =[ [NSString stringWithFormat:@"123%d",4]retain];
});
dispatch_ground_async(ground, dispatch_get_global_queue(0,0), ^{\
first =[ [NSString stringWithFormat:@"567%d",8]retain];
});
dispatch_ground_notify(ground, dispatch_get_global_queue(0,0), ^{
NSString *result = [NSString stringWithFormat:@"%@+%@"m first, second];
dispatch_async(dispatch_get_main_queue(0,0), ^{
///////////////////
}
[first release];
[second release];
});
});
注意:
dispatch_get_global_queue(),扎取一个已经存在并始终可用的全局队列,该函数接受两个参数:第一个用来指定优先级, 第二个目前未使用并且始终为零。
dispatch_get_main_queue(),该函数总是提供存在于主线程上的特殊队列, 并准备执行需要使用主线程的程序块。