我的这个应用程序是在 iPhone 4 发布时创建的。现在,此应用无法在 iPhone 4S 上运行。
我已将罪魁祸首部分确定为 GCD 部分。在这里:
dispatch_group_t my_group = dispatch_group_create();
dispatch_queue_t queue1 =
dispatch_queue_create("Queue 1", NULL);
dispatch_queue_t queue2 =
dispatch_queue_create("Queue 2", NULL);
dispatch_group_async(my_group, queue1, ^{
[self doStuff1];
});
dispatch_group_async(my_group, queue2, ^{
[self doStuff2];
});
dispatch_group_notify(my_group, dispatch_get_main_queue(), ^{
// this is block 3, this is to be executed after both queues end processing
// this is never executed on iPhone 4S, but is executed on iPhone4
// no error message, but execution never starts inside this block
});
思路是这样的:创建两个队列和一个组。我使用组异步地为两个队列触发任务。两者都完成后,该小组将启动另一组任务。
这项工作在 iPhone 4 上非常出色,但从未达到最后的 block 3。
有什么理由吗?有什么线索吗?
谢谢。
最佳答案
也许 doStuff1
和 doStuff2
正在死锁,或者其他什么东西阻塞了主线程? 4S 有多个内核,与 4 不同,因此您可能会遇到一些以前不会遇到的多线程锁定问题。
您确定这两个 block 实际上都已完成,并且主线程可用于运行生成的 block 吗?也许一些完整的代码(即 doStuff1 和 2 的主体)会有所帮助?
关于iPhone - Grand Central Dispatch 在 iPhone 4S 上无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8186798/