0

我创建了自己的 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]我得到了我想要的,除了这可能导致一些错误,因为主线程干扰了这些操作......

4

1 回答 1

0

操作的并发性是如何实现的?我怀疑您正在将事情分派到主线程,并且您也在-waitUntillAllOperationsAreFinished. 这当然会陷入僵局。

于 2012-05-27T13:09:23.023 回答