0
NSBlockOperation *blockOperation = ^{NSLog(@"This is an NSBlockOperation");};
NSOperationQueue *ownQueue = [[NSOperationQueue alloc] init];
[ownQueue setMaxConcurrentOperationCount:2];        
[ownQueue addOperation:blockOperation];

我只是在尝试NSBlockOperation,但是这个简单的代码以EXC_BAD_ACCESS. 代码位于 main 中,并由@autorelease.

libsystem_c.dylib`OSAtomicCompareAndSwapIntBarrier$VARIANT$mp:
0x7fff8b8dc524:  movl   %edi, %eax

libsystem_c.dylib`OSAtomicCompareAndSwap32$VARIANT$mp + 2:

0x7fff8b8dc526:  lock   
0x7fff8b8dc527:  cmpxchgl%esi, (%rdx)
0x7fff8b8dc52a:  sete   %al
0x7fff8b8dc52d:  movzbl %al, %eax
0x7fff8b8dc530:  ret    
0x7fff8b8dc531:  nopl   (%rax)

程序停止并指向0x7fff8b8dc526: lock

4

1 回答 1

2

您尝试将块分配给 a NSBlockOperation,但这是不同的类型。正确的是

NSBlockOperation *blockOperation = [NSBlockOperation blockOperationWithBlock:^{
    NSLog(@"This is an NSBlockOperation");
}];
于 2012-09-23T12:18:09.367 回答