分配队列时应用程序阻止 [英] App blocks while dipatching a queue

查看:68
本文介绍了分配队列时应用程序阻止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用XMPPFramework,并且在代码中有这样的方法:

Im using XMPPFramework and in it's code there's a method like this:

- (NSDictionary *)occupants
{
    if (dispatch_get_current_queue() == moduleQueue)
    {
        return occupants;
    }
    else
    {
        __block NSDictionary *result;

        dispatch_sync(moduleQueue, ^{//IT BLOCKS HERE, WITHOUT MESSAGE
            result = [occupants copy];
        });

        return [result autorelease];
    }
}

由于应用程序未执行任何操作,因此它不一致地阻塞(并非总是如此),我将其暂停,并且我看到线程已在那里停止,并且永远不会继续执行. 怎么了?有什么想法吗?

It blocks inconsistently, not always, since the app is not doing anything I pause it and I see the thread has stopped there, and it never continues to execute. What is wrong? Any ideas?

谢谢

推荐答案

您解释的行为与您尝试通过GCD在主线程上通过主线程发送执行操作时出现的行为完全匹配.因此,您应该检查moduleQueue是否是主队列,然后就是它.尝试检查是否是主队列,请跳过dispatch_sync块.

The behavior you explain perfectly matches with the one that appears when you try to send perform an operation on main thread via GCD while being on the main thread. So you should check if moduleQueue is the main queue, then this is it. Try checking if it is the main queue if it is, skip the dispatch_sync block.

这篇关于分配队列时应用程序阻止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆