@PEND
2020-04-13T14:50:13.000000Z
字数 1502
阅读 519
代码面试题
以下代码打印结果分别是什么?
NSLog(@"%@, 1", [NSThread currentThread]);dispatch_queue_t queue = dispatch_queue_create("com.test.queue", NULL);dispatch_sync(queue, ^{NSLog(@"%@, 2", [NSThread currentThread]);});NSLog(@"3");NSLog(@"------分割线------");NSLog(@"%@, 1", [NSThread currentThread]);dispatch_queue_t queue1 = dispatch_queue_create("com.test.queue", NULL);dispatch_async(queue1, ^{NSLog(@"%@, 2", [NSThread currentThread]);});NSLog(@"3");NSLog(@"------分割线------");NSLog(@"%@, 1", [NSThread currentThread]);dispatch_queue_t queue2 = dispatch_queue_create("com.test.queue", DISPATCH_QUEUE_CONCURRENT);dispatch_sync(queue2, ^{NSLog(@"%@, 2", [NSThread currentThread]);});NSLog(@"3");NSLog(@"------分割线------");NSLog(@"%@, 1", [NSThread currentThread]);dispatch_queue_t queue3 = dispatch_queue_create("com.test.queue", DISPATCH_QUEUE_CONCURRENT);dispatch_async(queue3, ^{for (int i = 0; i < 2; i++) {NSLog(@"block1 %@", [NSThread currentThread]);}});dispatch_async(queue3, ^{for (int i = 0; i < 2; i++) {NSLog(@"block2 %@", [NSThread currentThread]);}});NSLog(@"3");NSLog(@"------分割线------");NSLog(@"%@, 1", [NSThread currentThread]);dispatch_queue_t queue4 = dispatch_get_main_queue();dispatch_sync(queue4, ^{NSLog(@"%@, 2", [NSThread currentThread]);});NSLog(@"3");NSLog(@"------分割线------");NSLog(@"%@, 1", [NSThread currentThread]);dispatch_queue_t queue5 = dispatch_get_main_queue();dispatch_async(queue5, ^{for (int i = 0; i < 2; i++) {NSLog(@"block1 %@", [NSThread currentThread]);}});dispatch_async(queue5, ^{for (int i = 0; i < 2; i++) {NSLog(@"block2 %@", [NSThread currentThread]);}});NSLog(@"3");