问题描述
我正在将代码从 NSThread/NSConditionLock 移至 NSOperation。
我有一个 CPU 密集型操作,全速运行时需要大约 3 秒。我想放慢速度,所以它需要 5 分钟,以便在后台缓慢运行,CPU 占用很少。
我通过确定 1/1000 的工作已完成对 NSThread 执行此操作,而不是暂停到允许时间(5 分钟)的 1/1000 过去。
NSOperation 有没有一种干净的方法可以做到这一点?
我的旧代码:
if ([[[self render] lock] lockWhenCondition:kConditionThreadMustExit beforeDate:[self blockUntil]])
{
[[[self render] lock] unlock];
break;
}
// blockUntil will determine what percent of work has been done and will block until the
// same percentage of the allotted time has passed.
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)