Giter Club home page Giter Club logo

Comments (5)

skyline75489 avatar skyline75489 commented on May 14, 2024

你的问题表达不是很清晰。中间那个 dispatch_sync 会导致 “3” 执行完之后再执行 “4”。

from interview.

webMing avatar webMing commented on May 14, 2024

你的问题表达不是很清晰。中间那个 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.

skyline75489 avatar skyline75489 commented on May 14, 2024

线程。block 里面的代码已经开始执行了,就和 queue 的阻塞与否无关了。queue 的阻塞(你想表达的应该是串行和并行的区别)与否是 queue 本身的性质。

from interview.

webMing avatar webMing commented on May 14, 2024

线程。block 里面的代码已经开始执行了,就和 queue 的阻塞与否无关了。queue 的阻塞(你想表达的应该是串行和并行的区别)与否是 queue 本身的性质。

谢谢.

from interview.

gongdeyin avatar gongdeyin commented on May 14, 2024

dispatch_async 会异步执行,不会阻塞当前call thread,里面的block会在一个thread上跑,thread是主线程还是非主线程取决你的queue;
dispatch_sync 会同步执行,会阻塞当前call thread,里面block会搭载在当前线程上跑,thread是主线程还是非主线程取决你的queue;

block相当于是货车拉的货物,线程就是车,空车是不准发车,只有有货才能发,所以,这里如果说有阻塞,是阻塞在queue里面的block(货物),货物才决定执行(发车)。

from interview.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.