dispatch_queue_t queue1 = dispatch_get_main_queue();//主队列
dispatch_queue_t queue2 = dispatch_get_global_queue(0, 0);//全球队列
dispatch_queue_t queue3 = dispatch_queue_create("queue3", DISPATCH_QUEUE_SERIAL);//串行队列
dispatch_queue_t queue4 =dispatch_queue_create("queue4", DISPATCH_QUEUE_CONCURRENT);//并发队列
dispatch_sync(queue4, ^{//串行执行,不管是什么队列都会在当前线程执行,不会开子线程
NSLog(@"串行");
NSLog(@"%@",[NSThread currentThread]);
});
dispatch_async(queue4, ^{//异步并发
NSLog(@"异步并发");
NSLog(@"%@",[NSThread currentThread]);
});
//线程间相互通信
dispatch_async(queue4, ^{//异步并发
NSLog(@"%@",[NSThread currentThread]);
dispatch_async(queue1, ^{//回到主线程
NSLog(@"%@",[NSThread currentThread]);
});
});
网友评论