First understand your brother dispatch_async
//Do something dispatch_async(queue, ^{ //Do something else }); //Do More Stuff
You use dispatch_async to create a new thread. When you do this, the current thread will not stop. This means that //Do More Stuff can execute before //Do something else finish
What happens if you want to stop the current thread?
You do not use sending at all. Just write the code usually
//Do something //Do something else //Do More Stuff
Now say that you want to do something in the DIFFERENT stream, and still wait, as if to make sure that the files are executed sequentially .
There are many reasons for this. User interface updates, for example, are performed in the main thread.
What are you using dispatch_sync
//Do something dispatch_sync(queue, ^{ //Do something else }); //Do More Stuff
Here you got //Do something //Do something else and //Do More Stuff executed sequentially, although //Do something else is executed on another thread.
Usually, when people use a different thread, the whole goal is that something can be done without waiting. Suppose you want to load a lot of data, but you want the user interface to be smooth.
Therefore, dispatch_sync is rarely used. But it is there. I personally have never used this. Why not ask for sample code or a project that uses dispatch_sync.
J. Chang 05 Oct '12 at 4:15 2012-10-05 04:15
source share