Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
409 views
in Technique[技术] by (71.8m points)

semaphore - IOS semaphore_wait_trap on main thread causing hang in UI

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()

on the main thread (Queue)

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.

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.

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

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

Can I force it to remove the block??

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

Before suspending the hanging Queue:

Main Queue Stack

And the hanging thread:

Hanging Queue

And After Pausing and suspending the bad queue:

After Suspending

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...