【发布时间】:2013-09-25 15:31:25
【问题描述】:
我有这段代码:
dispatch_queue_t queue = dispatch_queue_create("Queue", NULL);
dispatch_async(queue, ^{
//accessing the internet
dispatch_sync(dispatch_get_main_queue(), ^{
[myObject myFunction];
});
});
在我的函数中:
dispatch_queue_t queue = dispatch_queue_create("anotherQueue", NULL);
dispatch_async(queue, ^{
//long task that takes seconds
dispatch_sync(dispatch_get_main_queue(), ^{
//this is never executed
NSLog(@"Got to main thread.");
//updating the UI
});
});
有人能解释为什么阻塞 ^{ NSLog(@"Got to main thread."); });不会被执行?
【问题讨论】:
-
嗯,看到这个我就头疼。移动 NSLog 以替换 [myObject myFunction]。那应该完成您正在尝试做的事情。为什么要在异步队列中的主队列中调用异步队列中的主队列。头又疼了!
标签: objective-c multithreading