Comments (5)
你的问题表达不是很清晰。中间那个 dispatch_sync 会导致 “3” 执行完之后再执行 “4”。
from interview.
你的问题表达不是很清晰。中间那个 dispatch_sync 会导致 “3” 执行完之后再执行 “4”。
👌,我的疑问是 dispatch_sync 阻塞的是global_queue 还是global_queue 中被派发执行任务的线程(现在已经有答案了:阻塞的是线程)?
个人觉得上图中很容易造成 dispatch_sync 阻塞的是queue,而不是queue中的线程.下面我做了补充.
途中省略的文字和上面箭头文字一样哈.
下面是我找到有助于理解的解释:
GCD provides and manages FIFO queues to which your application can submit tasks in the form of block objects. Work submitted to dispatch queues are executed on a pool of threads fully managed by the system. No guarantee is made as to the thread on which a task executes.see more
from interview.
线程。block 里面的代码已经开始执行了,就和 queue 的阻塞与否无关了。queue 的阻塞(你想表达的应该是串行和并行的区别)与否是 queue 本身的性质。
from interview.
线程。block 里面的代码已经开始执行了,就和 queue 的阻塞与否无关了。queue 的阻塞(你想表达的应该是串行和并行的区别)与否是 queue 本身的性质。
谢谢.
from interview.
dispatch_async 会异步执行,不会阻塞当前call thread,里面的block会在一个thread上跑,thread是主线程还是非主线程取决你的queue;
dispatch_sync 会同步执行,会阻塞当前call thread,里面block会搭载在当前线程上跑,thread是主线程还是非主线程取决你的queue;
block相当于是货车拉的货物,线程就是车,空车是不准发车,只有有货才能发,所以,这里如果说有阻塞,是阻塞在queue里面的block(货物),货物才决定执行(发车)。
from interview.
Related Issues (15)
- HTTP的生命周期 HOT 8
- 当重载父类中的属性时,父类和子类均会生成 set 和 get 方法 HOT 3
- 关于 layoutSubviews 被调用的时机 HOT 3
- 四个全局队列 HOT 3
- 严重缺页啊,哈哈 HOT 1
- 您好,发现了一个错误 HOT 2
- The AlertDialog pops up is doesn't call onPause method HOT 1
- 请求更新 Gitbook HOT 2
- 不再更新了吗?好多内容没有呢 HOT 1
- TLS应该是非对称加密算法 HOT 4
- 冒泡排序代码j的上界错了 HOT 2
- 这是窝工的前辈们写的嘛? HOT 1
- 图片地址错误/无法显示
- 可以提供一份 pdf 材料吗 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from interview.