What happens to the lock in IOS using @synchronized() when we call dispatch_async() within the block.
For ex:
id myID
-(void) foobar
{
@synchronized(myID){
dispatch_async(){ //do stuff with myID};
}
}
Is the lock still valid within the dispatch_async call? Or more importantly is there any drawbacks in using another @synchronized() call inside dispatch_async()?
The lock there would just prevent two different blocks being dispatched at once. However they're dispatched asynchronously, so they may be performed then or may be performed arbitrarily far in the future. The dispatch call also won't wait for them to complete.
So the stuff inside the block isn't synchronised. Options to achieve that with minimal changes are a synchronous dispatch or just @synchronizing within the block.
Depending on what you're doing, the best idea might be to establish a serial dispatch queue and dispatch your blocks onto that.