As the title, dispatch_sync() on main queue and main thread will cause deadlock, like that:
dispatch_sync(dispatch_get_main_queue(), ^{
NSLog(@"%@", [NSThread currentThread]);
});
But NSBlockOperation will not cause deadlock:
NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
NSLog(@"%@", [NSThread currentThread]);
}];
[operation start];
So, I don't understand why? This function does not return until the block has finished just like dispatch_sync, so why it doesn't cause deadlock? And what's the different between them?