NSRunLoop is receiving a strange selector; possible race condition tomfoolery?

孤街醉人 提交于 2019-12-11 20:55:50

问题


I've got some threads doing heavy work while my main thread handles the UI stuff. The threads callback to the main thread at times to update a progress bar.

All in all, it's not that stable. I've fixed problems relating to the logic, but one in particular persists. I've got some code that acts like a stop button, meaning that the thread won't try and renew itself the next time it comes around to check what's going on.

Sometimes, when I press the stop button, I receive this error:

-[NSRunLoop isEnabled]: unrecognized selector sent to instance...

It seems to happen if I hit the stop button towards the end of the thread's work phase. During this time, it doesn't do much except:

  • Release some OpenGL memory
  • Call a final method on the main thread
  • Drain its autorelease pool
  • And return

But frankly, the error message is too cryptic for me to even know where to begin. Can anyone shed some light on NSRunLoop, what this 'isEnabled' method might be, or a general stab at what might be going wrong?


回答1:


Try running with Zombies enabled. I wouldn't be surprised if one of the runloop objects from a thread is getting destroyed and overwritten by another object, but you've still got a stale pointer to where it used to be.



来源:https://stackoverflow.com/questions/3576724/nsrunloop-is-receiving-a-strange-selector-possible-race-condition-tomfoolery

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