EdwardEan's recent timeline updates
EdwardEan

EdwardEan

🏢  世界邦旅行网 / iOS攻城狮
V2EX member #30591, joined on 2012-12-13 19:40:04 +08:00
EdwardEan's recent replies
Apr 12, 2016
Replied to a topic by Dean iDev iOS GCD 线程死锁的疑问
接上一段回复内容:

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");
}];
});
Apr 12, 2016
Replied to a topic by Dean iDev iOS GCD 线程死锁的疑问
不知道题主有没有读过 dispatch_sync 方法的这一段注释:
As an optimization, dispatch_sync() invokes the block on the current thread when possible.
如果明白了请试着考虑下下面一段代码的输出结果:
About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3166 Online   Highest 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 22ms · UTC 12:50 · PVG 20:50 · LAX 05:50 · JFK 08:50
♥ Do have faith in what you're doing.