dngfng
dngfng

Reputation: 1943

Simple NSOperationQueue ends in EXC_BAD_ACCESS

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

I am just trying out NSBlockOperation, however this simple code ends with a EXC_BAD_ACCESS. The code is in main and surrounded by @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)

The Program stops and points at 0x7fff8b8dc526: lock

Upvotes: 0

Views: 561

Answers (1)

Martin R
Martin R

Reputation: 539765

You try to assign a block to a NSBlockOperation, but that are different types. Correct is

NSBlockOperation *blockOperation = [NSBlockOperation blockOperationWithBlock:^{
    NSLog(@"This is an NSBlockOperation");
}];

Upvotes: 2

Related Questions