主线程上的IOS semaphore_wait_trap导致UI挂起 [英] IOS semaphore_wait_trap on main thread causing hang in UI

查看:1340
本文介绍了主线程上的IOS semaphore_wait_trap导致UI挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在异步(串行)工作队列中有一个长时间运行的函数。
我知道有时这个函数会在特定的openCV调用中挂起。
由于某种原因,这个挂起也导致主线程挂起。
当暂停并进入调试模式时,我看到有一个调用

I have a long running function inside an asynchronous (serial) worker queue. I know that sometimes this function hangs inside a particular openCV call. For some reason this hang is also causing the main thread to hang. When pausing and entering debug mode I see that there is a call to

semaphore_wait_trap()

主线程(队列)

我可以暂停在调试模式下挂起线程(我的工作队列),然后此陷阱消失,GUI再次在电话上响应。

I can suspend the hanging thread (My worker queue) in debug mode and then this trap goes away and the GUI becomes responsive once again on the phone.

在取消暂停工作线程之后,GUI是响应1-2秒(我怀疑再次激活此线程)然后UI再次无响应。

After unpausing the worker thread the GUI is responsive for 1-2 seconds (I suspect until this thread is activated again) and then the UI becomes unresponsive once again.

此线程没有 dispatch_sync()调用主线程/队列

This thread makes no dispatch_sync() calls to the main thread/Queue

IOS是否可能暂停主线程(陷阱),因为工作者是长期运行?

Is it possible that IOS pauses the main thread ("traps" it) because the worker is long running?

我可以强行删除它吗?

我正在添加一些打印屏幕调试模式堆栈。

I am adding some print screens of the debug mode stack.

暂停挂起队列之前:

悬挂线程:

暂停和暂停坏队列后:

推荐答案

IOS是否可能暂停主线程(陷阱),因为工作人员长时间运行? - 没有。
我认为,您的问题与绘制或更改某些UI元素有关。并非所有函数都可以从后台线程调用(例如,必须在主线程中完成对UI元素的更改)。在你的串行队列中,如果任何方法需要更改UI元素,你必须在主线程上调用它,例如

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

这篇关于主线程上的IOS semaphore_wait_trap导致UI挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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