我已经创建了自己的NSOperation子类,现在我想让它的一些实例并行运行。由于这是一个并发的操作,我已经覆盖了
- (void)start {
[self willChangeValueForKey:@"isExecuting"];
isExecuting = YES;
[self didChangeValueForKey:@"isExecuting"];
error=NO;
startedSection=NO;
// start the task
[task launch];
}
- (BOOL)isConcurrent {
return YES;
}
- (BOOL)isExecuting {
return isExecuting;
}
- (BOOL)isFinished {
return isFinished;
}
并在操作完成时执行以下代码:
[self willChangeValueForKey:@"isExecuting"];
[self willChangeValueForKey:@"isFinished"];
isExecuting = NO;
isFinished = YES;
[self didChangeValueForKey:@"isExecuting"];
[self didChangeValueForKey:@"isFinished"];
当我将操作添加到[myQueue waitUntillAllOperationsAreFinished]
之后添加myQueue
时,所有操作都没有启动!当我删除[myQueue waitUntillAllOperationsAreFinished]
时,我得到了我想要的东西,除了这可能导致一些错误,因为主线程干扰了这些操作......
答案 0 :(得分:0)
如何实现操作的并发性?我怀疑你是在向主线程发送内容,而你也在-waitUntillAllOperationsAreFinished
的主线程中阻塞了。那当然会陷入僵局。