#pragma mark 串行同步
/*
//1.创建一个串行队列
dispatch_queue_t queueSerialSync = dispatch_queue_create("queueSerialSync", DISPATCH_QUEUE_SERIAL);
//2. 在队列中同步执行 不具有开启新线程的能力
dispatch_sync(queueSerialSync, ^{
NSLog(@"%@",[NSThread currentThread]);
});
dispatch_sync(queueSerialSync, ^{
NSLog(@"%@",[NSThread currentThread]);
});
dispatch_sync(queueSerialSync, ^{
NSLog(@"%@",[NSThread currentThread]);
});
*/
#pragma mark 串行异步
/*
//1.创建一个串行队列
dispatch_queue_t queueSerialAsync =dispatch_queue_create("queueSerialAsync", DISPATCH_QUEUE_SERIAL);
//2. 在队列中同步执行 不具有开启新线程的能力
dispatch_async(queueSerialAsync, ^{
NSLog(@"%@",[NSThread currentThread]);
});
dispatch_async(queueSerialAsync, ^{
NSLog(@"%@",[NSThread currentThread]);
});
dispatch_async(queueSerialAsync, ^{
NSLog(@"%@",[NSThread currentThread]);
});
*/
#pragma mark 并行同步
/*
//1.创建一个并行队列 可有多个线程
dispatch_queue_t queueConcurrentSync = dispatch_queue_create("queueConcurrentSync", DISPATCH_QUEUE_CONCURRENT);
//2. 在队列中同步执行 不具有开启新线程的能力
dispatch_sync(queueConcurrentSync, ^{
NSLog(@"%@",[NSThread currentThread]);
});
dispatch_sync(queueConcurrentSync, ^{
NSLog(@"%@",[NSThread currentThread]);
});
dispatch_sync(queueConcurrentSync, ^{
NSLog(@"%@",[NSThread currentThread]);
});
*/
#pragma mark 并行异步
//1.创建一个并行队列 可有多个线程 (这是系统里面封装的一个并行队列)
dispatch_queue_t queueConcurrentAsync = dispatch_get_global_queue(0, 0);
/*
四种优先级 从上到下降低
* - DISPATCH_QUEUE_PRIORITY_HIGH: QOS_CLASS_USER_INITIATED
* - DISPATCH_QUEUE_PRIORITY_DEFAULT: QOS_CLASS_DEFAULT
* - DISPATCH_QUEUE_PRIORITY_LOW: QOS_CLASS_UTILITY
* - DISPATCH_QUEUE_PRIORITY_BACKGROUND: QOS_CLASS_BACKGROUND
*/
/*
//2. 异步方式执行
dispatch_async(queueConcurrentAsync, ^{
NSLog(@"%@",[NSThread currentThread]);
});
dispatch_async(queueConcurrentAsync, ^{
NSLog(@"%@",[NSThread currentThread]);
});
dispatch_async(queueConcurrentAsync, ^{
NSLog(@"%@",[NSThread currentThread]);
});
*/
#pragma 获取到主队列
//dispatch_queue_t mainQueue = dispatch_get_main_queue();
#pragma GCD 应用
//找到全局的并行队列
dispatch_queue_t content = dispatch_get_global_queue(0, 0);
//找到组
dispatch_group_t group = dispatch_group_create();
//添加任务
dispatch_group_async(group, content, ^{
NSLog(@"%@",[NSThread currentThread]);
});
dispatch_group_async(group, content, ^{
NSLog(@"%@",[NSThread currentThread]);
});
dispatch_group_async(group, content, ^{
NSLog(@"%@",[NSThread currentThread]);
});
//监听完成 上面任务全部完成后触发
dispatch_group_notify(group, content, ^{
NSLog(@"任务完成");
});