The main
queue is no different than any other queue with regard to whether you can enqueue something to it synchronously or asynchronously.
The only rule you must adhere to is to never use sync
to enqueue something onto the same queue currently being used. That will cause a deadlock. Again, this is true no matter the queue, main or otherwise.
To answer your question "Is the same as" - no, it is not the same. Assuming both sets of code are being called from some background queue, in the first set of code, the background queue will keep on moving along without regard to when the two blocks eventually get executed on the main queue. In the second set of code (using sync
), the background queue blocks each time until each block of code is run on the main queue.
If both sets of code are being called from the main queue, then there is a bigger difference. The first set of code (with async
) keeps working. The second set of code (with sync
) will cause the main queue to block at the first call to sync
and your app will become unresponsive until the user (or the OS) kills it.
The only possibly relevant difference between the main queue and other queues is that the main queue is always a serial queue while background queues can be either serial or concurrent. But both have valid uses for using sync
or async
as long as you avoid using sync
where both queues are the same.