Executing a block inside @synchronized seems to negate the lock.
- (void)method {
@synchronized(self) {
if(ivar == nil) {
ivar = [myBlock() retain];
}
}
}
The instance variable ivar is not written in any other location.
I’ve observed that the block myBlock sometimes is executed twice in my application.
How can this ever happen? How to avoid this an do a real working lock?
The lock worked fine as
synchronizedlocks only threads, and the same thread was accessing the region twice. The problem was, thatmyBlockexecuted itself inside under some circumstances.