面试被问到这样一个问题,appdelegate持有一个nsthread对象,然后在viewcontroller里利用
[NSObject performSelector:@selector(test) onThread:thread withObject:self waitUntilDone:YES];
执行任务,任务会执行吗?为什么?
当时没细想,直接说不会,因为子线程runloop不开启。
显然这么说是不对的。正确答案是这样的,一般情况下,一个线程执行完任务就会退出,虽然强持有这个thread,但是cpu没有给它分配资源,所以这个时候就要用到runloop,runloop可以让线程一直或者,有任务时执行任务,没有任务是休眠。