Are they guaranteed to be executed in the same order?
Yes.
Will / could the
isObjectInQueue
execute first?
Yes.
The reason for the yes to both answers is you should consider threading. Which is presumably why you are using the serial queue in the first place. You are making access to that queue thread safe.
Basically, the blocks will execute in the order in which they are put on the serial queue. That is 100% guaranteed. However, if multiple threads are hammering away at this then one thread may get in first to read something from the queue before another has had chance to add it.
In other words, does dispatch_async perform exactly the same as
dispatch_sync
(scheduling the block immediately) except that it doesn't block the calling thread?
That's right. In both cases the block is added to the queue. It is added immediately. dispatch_sync
just waits for the block to finish before returning whereas dispatch_async
returns immediately.