假设我按顺序呼叫dispatch_async()
三次:
dispatch_async(dispatch_get_main_queue(),
^{
[self doOne];
});
// some code here
dispatch_async(dispatch_get_main_queue(),
^{
[self doTwo];
});
// more code here
dispatch_async(dispatch_get_main_queue(),
^{
[self doThree];
});
这总是会像
那样执行 [self doOne]
,[self doTwo]
,然后是[self doThree]
,或订单是否有保障?
在这种情况下,问题可能是主队列是串行还是并发。
答案 0 :(得分:15)
来自文档:
dispatch_get_main_queue
返回与应用程序关联的串行调度队列 主线。
因此主队列是串行队列,[self doOne]
,[self doTwo]
,[self doThree]
按顺序依次执行。
答案 1 :(得分:4)
Concurrency Programming Guide, About Dispatch Queues:
主调度队列是全局可用的串行队列,它在应用程序的主线程上执行任务。 [强调我的]