1
- (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了什么?

4

0 回答 0