1、dispatch_group
dispatch_group_t group = dispatch_group_create();dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{ // 执行1个耗时的异步操作});dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{ // 执行1个耗时的异步操作});dispatch_group_notify(group, dispatch_get_main_queue(), ^{ // 等前面的异步操作都执行完毕后,回到主线程...});
2、dispatch_barrier_async
dispatch_queue_tqueue =dispatch_queue_create("12312312",DISPATCH_QUEUE_CONCURRENT);dispatch_async(queue,^{ NSLog(@"----1-----%@", [NSThread currentThread]);});dispatch_async(queue,^{ NSLog(@"----2-----%@", [NSThread currentThread]);});dispatch_barrier_async(queue,^{ NSLog(@"----barrier-----%@", [NSThread currentThread]);});dispatch_async(queue,^{ NSLog(@"----3-----%@", [NSThread currentThread]);});dispatch_async(queue,^{ NSLog(@"----4-----%@", [NSThread currentThread]);});