NSRunLoop收到一个奇怪的选择器.可能的种族条件假装? [英] NSRunLoop is receiving a strange selector; possible race condition tomfoolery?

查看:67
本文介绍了NSRunLoop收到一个奇怪的选择器.可能的种族条件假装?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的主线程处理UI内容时,我有一些线程在做繁重的工作.线程有时会回调到主线程以更新进度条.

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]:无法识别的选择器已发送到实例...

-[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:

  • 释放一些OpenGL内存
  • 在主线程上调用最终方法
  • 排空自动释放池
  • 然后返回

但是坦率地说,错误消息对于我来说太神秘了,甚至不知道从哪里开始.任何人都可以对NSRunLoop,这个'isEnabled'方法可能是什么,或者是对可能出了什么问题的一般刺探有所了解吗?

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?

推荐答案

尝试在启用僵尸的情况下运行.如果线程中的一个runloop对象之一被另一个对象破坏并覆盖了,我不会感到惊讶,但是您仍然有一个指向它过去位置的陈旧指针.

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.

这篇关于NSRunLoop收到一个奇怪的选择器.可能的种族条件假装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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