App blocks while dipatching a queue

ぐ巨炮叔叔 提交于 2019-11-28 11:54:13

问题


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];
    }
}

[EDIT] 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?

Thanks


回答1:


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.




回答2:


Blocks sometimes need to retain variables to ensure they are available when they execute. If you use a local variable inside a block, you should initialise it to zero where you declare it outside the block.



来源:https://stackoverflow.com/questions/10315645/app-blocks-while-dipatching-a-queue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!