// // ViewController.m // GCD // // Created by mac on 16/4/21. // Copyright © 2016年 mac. All rights reserved. // #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; } - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { /** * 1)dispatch_sync:同步,不具备开启线程的能力 2)dispatch_async:异步,具备开启线程的能力 并发队列:多个任务可以同时执行 串行队列:多个任务,排队执行,一个任务执行完,再执行下一个任务 */ //获取并发的全局队列 dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); //将 任务 添加到 全局队列 中去 异步执行 dispatch_async(queue, ^{ NSLog(@"1111==%@", [NSThread currentThread]); }); dispatch_async(queue, ^{ NSLog(@"2222==%@", [NSThread currentThread]); }); dispatch_async(queue, ^{ NSLog(@"3333==%@", [NSThread currentThread]); }); dispatch_async(queue, ^{ NSLog(@"4444==%@", [NSThread currentThread]); }); dispatch_async(queue, ^{ NSLog(@"5555==%@", [NSThread currentThread]); }); } @end