dispatch_queue_t myQueue = dispatch_queue_create("com.team", NULL);
NSLog(@"task1 == %@",[NSThread currentThread]);
dispatch_sync(myQueue, ^{
// task2 为什么在主线程执行,不是应该在block追加到的线程执行吗,就像task4一样,block里的线程应该和 dispatch_sync 的第一个参数的线程相同
NSLog(@"task2 == %@",[NSThread currentThread]);
});
dispatch_async(myQueue, ^{
NSLog(@"task3 == %@",[NSThread currentThread]);
dispatch_sync(dispatch_get_main_queue(), ^{
NSLog(@"task4 == %@",[NSThread currentThread]);
});
});

编译器会有优化,他发现sync方式,就可能直接同一个线程执行