- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSLog(@"begin async:%@", [NSThread currentThread]);
dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSLog(@"in sync:%@", [NSThread currentThread]);
});
NSLog(@"end async:%@", [NSThread currentThread]);
});
NSLog(@"end main");
}
Why do I get such result as below?
- end main
- begin async:{number = 2, name = (null)}
- in sync:{number = 2, name = (null)}
- end async:{number = 2, name = (null)}
As apple developer document said:
Submits a block to a dispatch queue for synchronous execution. Unlike dispatch_async, this function does not return until the block has finished. Calling this function and targeting the current queue results in deadlock.
"in sync" and "end async" will never log out, is that correct?