在客观C, 我让我的程序中使用while循环在iOS编程中使用while(true)语句是一种有效的方法?
doInitialize()
{
dispach_group_t loadDataGroup=dispatch_group_create();
dispatch_group_async(loadDataGroup,...get_global_queue(..),0),^{
renewauth();
}
dispatch_group_notify(loadDataGroup,...get_global_queue(..),0),^{
//Do other tasks once renew session has completed...
}
}
renewauth()
{
RenewAuthTokenInProgress=true;
startRenewThread();
**while (RenewAuthTokenInProgress);**
}
反过来startRenewThread()函数里面也进行dispatch_async操作等。所以我必须使renewAuth()等待。
一旦更新成功,startRenewThread中的异步任务将更新bool变量。
除了dispatch_groups之外,还有更好的方法吗? 让其他线程与while(true)语句等待是否好?
忙碌的等待是一个可怕的想法。为什么你要在后台运行这个更新功能? – Thilo
如果你使用异步路由,dispatch_groups有什么问题? – Thilo
假设RenewAuthTokenInProgress保持一段时间,然后是你的iPhone会变热。您将以100%运行其中一个内核。它也会使你的电池变平。 – TJA