 |
|
EdwardEan
🏢 世界邦旅行网 / iOS攻城狮
V2EX member #30591, joined on 2012-12-13 19:40:04 +08:00
|
EdwardEan's recent replies
接上一段回复内容:
dispatch_sync(dispatch_get_global_queue(0, 0), ^{
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
NSLog(@"First");
}];
[[NSOperationQueue currentQueue] addOperationWithBlock:^{
NSLog(@"Three");
}];
__block id observer = [[NSNotificationCenter defaultCenter] addObserverForName:@"MyNotif" object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
NSLog(@"Receive Notif");
[[NSNotificationCenter defaultCenter] removeObserver:observer];
}];
[[NSOperationQueue currentQueue] addOperationWithBlock:^{
NSLog(@"Forth");
}];
[[NSNotificationCenter defaultCenter] postNotificationName:@"MyNotif" object:self];
[[NSOperationQueue currentQueue] addOperationWithBlock:^{
NSLog(@"Five");
}];
});
不知道题主有没有读过 dispatch_sync 方法的这一段注释:
As an optimization, dispatch_sync() invokes the block on the current thread when possible.
如果明白了请试着考虑下下面一段代码的输出结果: