iPhone - Grand Central Dispatch在iPhone 4S上无法正常工作

Spa*_*Dog 3 iphone cocoa-touch grand-central-dispatch ipad ios

我有这个应用程序是我的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
});
Run Code Online (Sandbox Code Playgroud)

这个想法是这样的:创建了两个队列和一个组.我使用该组以异步方式为两个队列启动任务.两者完成后,该组将触发另一个任务块.

这项工作非常适用于iPhone 4,但最终的第3块永远不会到达.

有什么理由吗?有线索吗?

谢谢.

Jes*_*sak 5

也许doStuff1并且doStuff2正在陷入僵局,或者其他什么阻碍主线程?4S有多个内核,与4不同,因此可能会遇到一些您以前从未见过的多线程锁定问题.

你确定两个块实际上都在完成,并且主线程可以运行生成的块吗?也许一些完整的代码(即doStuff1和2的主体)会有所帮助吗?

  • 测试多核理论的一种方法(也是我的猜测也是如此)在iPad 2上运行.从来没有对线程问题的保证,但是它们确实倾向于使用多个核心更容易暴露. (2认同)