Failing to see how @synchronized works with asynchronous blocks
<p>Suppose I have a function like the following one, that is called 30 times per second (this code is a simplification of a more complex code created by Apple that I am trying to understand. The idea of Apple's original code is this: like I said <code>doSomethingWithImage</code> is called 30 per second. So, the whole method has 1/30 of a second to do everything but imagine that <code>doSomethingThatWillTakeTime</code> takes more than expected and <code>doSomethingWithImage</code> is called again, while <code>doSomethingThatWillTakeTime</code> is already being executed. If this is the case, the code has to drop that image and do nothing. </p>

<pre><code>// code...
@synchronized (self);
  [self doSomethingWithImage:image];
}

// ...

// call under @synchronized( self )
- (void)doSomethingWithImage:(UIImage *)image
{
    self.myImage = image;

    [self executeBlockAsync:^{ 

        UIImage *myImage = nil;

        @synchronized( self ) 
        {
            myImage = self.myImage; 
            if (myImage) { 
                self.myImage = nil; // drop the image
            }
        }

        if ( myImage ) { 
            [self doSomethingThatWillTakeTime:myImage];  
        }
    }];
}


 (void)executeBlockAsync:(dispatch_block_t)block
{
    dispatch_async( _myQueue, ^{
            callbackBlock();
    } );
}
</code></pre>

<p>My problem is that looking at this code I cannot see how this is doing that. I do not have a mental image of what lines are being execute in which order for that to occur. Probably I do not understand the role of <code>@synchronized</code> in doing that, on what exactly is being locked or not.</p>