I'm trying to understand the differences between the types of queues. As I understand it there are 3 types:
What I'm wondering is: What are the differences between dispatch_sync and dispatch_async when submitted to each kind of queue? This is how I understand it thus far:
dispatch_sync(global_queue)^
{
// blocks are executed one after the other in no particular order
// example: block 3 executes. when it finishes block 7 executes.
}
dispatch_async(global_queue)^
{
// blocks are executed concurrently in no particular order
// example: blocks 2,4,5,7 execute at the same time.
}
dispatch_sync(main_queue)^
{
// blocks are executed one after the other in the order they were submitted
// example: block 1 executes. when it finishes block 2 will execute and so forth.
}
dispatch_async(main_queue)^
{
// blocks are executed concurrently in the order they were submitted
// example: blocks 1-4 (or whatever amount of threads the system can handle at one time) will fire at the same time.
// when the first block completes block 5 will then execute.
}
I'd like to know how much my perception of this is correct.
the difference between dispatch_sync and dispatch_async is kind like sendmessage and postmessage in windows API. dispatch_sync Submits a block object for execution on a dispatch queue and waits until that block completes. dispatch_async Submits a block for asynchronous execution on a dispatch queue and returns immediately.
The target queue determines whether the block is invoked serially or concurrently with respect to other blocks submitted to that same queue. Independent serial queues are processed concurrently with respect to each other.
you should really read the document first carefully before post the question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With