IOS semaphore_wait_trap on main thread causing hang in UI

半腔热情 提交于 2019-11-29 05:28:43
Fahri Azimov

Is it possible that IOS pauses the main thread ("traps" it) because the worker is long running? - NO. I think, your problem is related to drawing or changing some UI elements. Not all functions can be called from background thread (e.g. changes to UI elements has to be done in main thread.). In your serial queue, if any method needs to change UI elements, you have to call it on main thread e.g

dispatch_async(dispatch_get_main_queue(), ^{
                //do some main thread job here
            });
)

Maybe you just forgot to retain a variable into dispatch function call (As for me I was omitted a static keyword before dispatch_once_t declaration and dispatch can't process with inline function). The stack trace was just like yours. That was my fault.

+ (instancetype)sharedInstance
{
    (static was omitted) dispatch_once_t once;
    static id sharedInstance;
    dispatch_once(&once, ^{
        sharedInstance = [[self alloc] init];
    });
    return sharedInstance;
} 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!