所以我正在启动一个新的 NSThread,我希望以后可以通过调用performSelector:onThread:...
. 根据我对调用该方法的理解,该方法将该调用添加到该线程上的 runloop,因此在其下一次迭代中,它将弹出所有这些调用并随后调用它们,直到没有任何东西可以调用。所以我需要这种功能,一个准备好工作的空闲线程,我可以调用它。我当前的代码如下所示:
- (void)doInitialize
{
mThread = [[NSThread alloc] initWithTarget:self selector:@selector(runThread) object:nil];
[mthread start];
}
- (void)runThread
{
NSAutoReleasePool *pool = [[NSAutoReleasePool alloc] init];
// From what I understand from the Google machine is that this call should start the
// runloop on this thread, but it DOESN'T. The thread dies and is un-callable
[[NSRunLoop currentRunLoop] run];
[pool drain];
}
- (void)scheduleSomethingOnThread
{
[self performSelector:@selector(hardWork) onThread:mThread withObject:nil waitUntilDone:NO];
}
但是线程没有保持活动状态,并且 performSelector:onThread 不做任何事情。我该如何以正确的方式解决这个问题?