我试图了解队列类型之间的差异。据我了解,有3种类型:
- 全局队列 - 并发 - 无论顺序如何,块都会尽快执行
- 主队列 - 串行 - 块在提交时执行
- 私有队列 - 串行
我想知道的是:dispatch_sync 和 dispatch_async 在提交到每种队列时有什么区别?到目前为止,我是这样理解的:
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.
}
我想知道我对此的看法在多大程度上是正确的。