Grand Central Dispatch async vs sync [英] Grand Central Dispatch async vs sync

查看:108
本文介绍了Grand Central Dispatch async vs sync的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读关于GCD调度队列的文档,并且在其中他们说队列是FIFO,所以我想知道这对异步/同步调度有什么影响?

I'm reading the docs on dispatch queues for GCD, and in it they say that the queues are FIFO, so I am woundering what effect this has on async / sync dispatches?

来自我的理解异步按顺序执行事情,同时执行串行事件..

from my understand async executes things in the order that it gets things while sync executes things serial..

但是当你编写GCD代码时,你决定事情发生的顺序..所以只要你知道你的代码中发生了什么,你应该知道事情的执行顺序..

but when you write your GCD code you decide the order in which things happen.. so as long as your know whats going on in your code you should know the order in which things execute..

我的问题是,异步的好处在这里?我在理解这两件事时遗漏了一些东西。

my questions are, wheres the benefit of async here? am I missing something in my understanding of these two things.

推荐答案

同步意味着函数将阻塞当前线程,直到它完成,async意味着它将在后台处理,函数将不会阻塞当前线程。

sync means the function WILL BLOCK the current thread until it has completed, async means it will be handled in the background and the function WILL NOT BLOCK the current thread.

如果要串行执行块,请检查串行调度的创建队列

If you want serial execution of blocks check out the creation of a serial dispatch queue

这篇关于Grand Central Dispatch async vs sync的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆