- (void)viewDidLoad
{
[super viewDidLoad];
dispatch_async(dispatch_queue_create("oneQueue", DISPATCH_QUEUE_SERIAL), ^
{
[self syncAction];
});
// CFRunLoopRun(); // 1
NSLog(@"mainQueue execut 1");
}
- (void)syncAction
{
dispatch_sync(dispatch_get_main_queue(), ^
{
// CFRunLoopStop(CFRunLoopGetCurrent());
NSLog(@"mainQueue execut 2"); // 2
});
}
如果我评论CFRunLoopRun();
和CFRunLoopStop(CFRunLoopGetCurrent());
输出:
mainQueue execut 1
mainQueue execut 2
但如果我不发表CFRunLoopRun();
评论CFRunLoopStop(CFRunLoopGetCurrent());
输出:
mainQueue execut 2
mainQueue execut 1
我一直认为,如果viewDidLoad
不执行编译,mainQueue
就不会执行新的功能块,但为什么CFRunLoopRun
可以让mainQueue
执行跳过当前功能并执行其他稍后添加的新块asyncQueue
。而何时CFRunLoopStop(CFRunLoopGetCurren))
,viewDidLoad
继续执行。做CFRunLoop
了什么?