I read that dispatch_sync()
would block the current thread and won't return back to it until the task that one would like to do synchronously was finished on a serial queue that dispatch_sync()
requires to work on.
So basically it would stop the current thread and perform the task it has.
If that, why bother having another queue for this kind of task, why cannot we just put the task on the current thread.
After all, doing the task would block the current thread anyway.
Since dispatch_sync()
wouldn't open another thread, then why do we bother opening another queue to do the task rather than doing it on the current queue/thread?
Hope I describe my confusion here clearly.
I am here comparing using dispatch_sync()
on another queue with using the current thread/queue directly, so what I would like to know is in what use case, using dispatch_sync()
on another queue would be better than using only the current queue.
This should be relevant to thread-safe
and synchronization
issue.