- (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できるのはなぜだと思いますか。そして、実行を続けます。どうした?mainQueueasyncQueueCFRunLoopStop(CFRunLoopGetCurren))viewDidLoadCFRunLoop