• <bdo id='M8rvP'></bdo><ul id='M8rvP'></ul>

      <i id='M8rvP'><tr id='M8rvP'><dt id='M8rvP'><q id='M8rvP'><span id='M8rvP'><b id='M8rvP'><form id='M8rvP'><ins id='M8rvP'></ins><ul id='M8rvP'></ul><sub id='M8rvP'></sub></form><legend id='M8rvP'></legend><bdo id='M8rvP'><pre id='M8rvP'><center id='M8rvP'></center></pre></bdo></b><th id='M8rvP'></th></span></q></dt></tr></i><div id='M8rvP'><tfoot id='M8rvP'></tfoot><dl id='M8rvP'><fieldset id='M8rvP'></fieldset></dl></div>
      <tfoot id='M8rvP'></tfoot>

    1. <small id='M8rvP'></small><noframes id='M8rvP'>

      1. <legend id='M8rvP'><style id='M8rvP'><dir id='M8rvP'><q id='M8rvP'></q></dir></style></legend>

      2. iOS开发中的“线程"和“队列"有什么区别?

        What is the difference between #39;thread#39; and #39;queue#39; in iOS development?(iOS开发中的“线程和“队列有什么区别?)

        <small id='WtFBQ'></small><noframes id='WtFBQ'>

          <tbody id='WtFBQ'></tbody>
        <i id='WtFBQ'><tr id='WtFBQ'><dt id='WtFBQ'><q id='WtFBQ'><span id='WtFBQ'><b id='WtFBQ'><form id='WtFBQ'><ins id='WtFBQ'></ins><ul id='WtFBQ'></ul><sub id='WtFBQ'></sub></form><legend id='WtFBQ'></legend><bdo id='WtFBQ'><pre id='WtFBQ'><center id='WtFBQ'></center></pre></bdo></b><th id='WtFBQ'></th></span></q></dt></tr></i><div id='WtFBQ'><tfoot id='WtFBQ'></tfoot><dl id='WtFBQ'><fieldset id='WtFBQ'></fieldset></dl></div>

            • <legend id='WtFBQ'><style id='WtFBQ'><dir id='WtFBQ'><q id='WtFBQ'></q></dir></style></legend>

              <tfoot id='WtFBQ'></tfoot>
                  <bdo id='WtFBQ'></bdo><ul id='WtFBQ'></ul>

                  本文介绍了iOS开发中的“线程"和“队列"有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我是 iOS 开发的新手.现在我对线程"和队列"这两个概念感到很困惑.我所知道的是它们都是关于多线程编程的.谁能为我解释这两个概念以及它们之间的区别?提前致谢!

                  I am new to iOS development. Now I am quite confused about the two concepts: "thread" and "queue". All I know is that they both are about multithread programming. Can anyone interpret those two concepts and the difference between them for me? Thanks in advance!

                  推荐答案

                  在阅读我的答案之前,您可能需要考虑阅读此内容 - 从线程迁移

                  Before you read my answer you might want to consider reading this - Migrating away from Threads

                  我将讨论保持在理论上,因为您的问题没有任何代码示例.这两种结构都是提高应用程序响应能力和提高应用程序响应能力所必需的.可用性.

                  I am keeping the discussion theoretical as your question does not have any code samples. Both these constructs are required for increasing app responsiveness & usability.

                  消息队列是一种数据结构,用于保存从发送消息到接收者检索并对其采取行动的消息.通常,队列被用作连接"(数据)生产者和连接"生产者的一种方式.消费者(数据).

                  A message queue is a data structure for holding messages from the time they're sent until the time the receiver retrieves and acts on them. Generally queues are used as a way to 'connect' producers (of data) & consumers (of data).

                  线程池是执行某种处理的线程池.线程池通常会附加某种线程安全队列(参考消息队列),以允许您将要完成的作业排队.这里的队列通常被称为任务队列".

                  A thread pool is a pool of threads that do some sort of processing. A thread pool will normally have some sort of thread-safe queue (refer message queue) attached to allow you to queue up jobs to be done. Here the queue would usually be termed 'task-queue'.

                  因此,线程池可以存在于您的生产者端(生成数据)或消费者端(处理数据).而传递"这些数据的方法是通过队列.为什么需要这个中间人"——

                  So in a way thread pool could exist at your producer end (generating data) or consumer end (processing the data). And the way to 'pass' that data would be through queues. Why the need for this "middleman" -

                  1. 它将系统解耦.生产者不了解消费者和反之亦然.
                  2. 如果生产者数据出现峰值,消费者不会受到数据的轰炸.队列长度会增加,但消费者是安全的.

                  示例:

                  在 iOS 中,主线程(也称为 UI 线程)非常重要,因为它负责将事件分派给适当的小部件,这包括绘图事件,基本上是用户看到的 UI 和相互作用.

                  In iOS the main thread, also called the UI thread, is very important because it is in charge of dispatching the events to the appropriate widget and this includes the drawing events, basically the UI that the user sees & interacts.

                  如果您触摸屏幕上的按钮,UI 线程会将触摸事件分派给应用程序,然后应用程序设置其按下状态并向事件 queue 发送请求.UI 线程将请求出列并通知小部件重绘自身.

                  If you touch a button on screen, the UI thread dispatches the touch event to the app, which in turn sets its pressed state and posts an request to the event queue. The UI thread dequeues the request and notifies the widget to redraw itself.

                  这篇关于iOS开发中的“线程"和“队列"有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  what#39;s property copy means in Cocoa#39;s Framework?(like UITabBar#39;s items property)(Cocoa 框架中的属性副本是什么意思?(如 UITabBar 的 items 属性))
                  Difference between retain and copy?(保留和复制的区别?)
                  Can`t copy file from bundle to documents directory in iOS(无法将文件从捆绑包复制到 iOS 中的文档目录)
                  Automatically copy property values from one object to another of a different type but the same protocol (Objective-C)(自动将属性值从一个对象复制到另一个类型不同但协议相同的对象 (Objective-C))
                  What is the difference between quot;copyquot; and quot;retainquot;?(“复制和“复制有什么区别?和“保留?)
                  Copy text to clipboard with iOS(使用 iOS 将文本复制到剪贴板)
                  <legend id='9UZCP'><style id='9UZCP'><dir id='9UZCP'><q id='9UZCP'></q></dir></style></legend>

                    <tbody id='9UZCP'></tbody>
                  1. <tfoot id='9UZCP'></tfoot>

                      <bdo id='9UZCP'></bdo><ul id='9UZCP'></ul>
                      • <i id='9UZCP'><tr id='9UZCP'><dt id='9UZCP'><q id='9UZCP'><span id='9UZCP'><b id='9UZCP'><form id='9UZCP'><ins id='9UZCP'></ins><ul id='9UZCP'></ul><sub id='9UZCP'></sub></form><legend id='9UZCP'></legend><bdo id='9UZCP'><pre id='9UZCP'><center id='9UZCP'></center></pre></bdo></b><th id='9UZCP'></th></span></q></dt></tr></i><div id='9UZCP'><tfoot id='9UZCP'></tfoot><dl id='9UZCP'><fieldset id='9UZCP'></fieldset></dl></div>

                        <small id='9UZCP'></small><noframes id='9UZCP'>