我是多线程的新手,需要一些建议。

我在代码中使用ARC。

问题:我已在我的应用程序中设置了NSTimer,以每隔一秒触发一次,该方法创建并启动了这样的线程

//Create a new thread
mSomeThread = [[NSThread alloc] initWithTarget:self selector:@selector(someMethod) object:nil];

//start the thread
[mSomeThread start];

其中mSomeThread是一个ivar

假设mSomeThread的执行花费了超过1秒的时间,并且mSomeThread被第二次分配,即根据ARC的“规则”,其释放之前被分配了更多的时间。

这是否意味着第一个线程没有完成而被迫完成?

最佳答案

NSThread在执行期间会自行保留。重置mSomeThread不会导致正在运行的线程过早终止,这没有任何风险。

关于iphone - 通过多线程实现的最佳方法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10868748/

10-10 22:24