zoukankan      html  css  js  c++  java
  • run loop

    Run Loops

    A run loop is a piece of infrastructure used to manage events arriving asynchronously on a thread. A run loop works by monitoring one or more event sources for the thread. As events arrive, the system wakes up the thread and dispatches the events to the run loop, which then dispatches them to the handlers you specify. If no events are present and ready to be handled, the run loop puts the thread to sleep. 

    You are not required to use a run loop with any threads you create but doing so can provide a better experience for the user. Run loops make it possible to create long-lived threads that use a minimal amount of resources. Because a run loop puts its thread to sleep when there is nothing to do, it eliminates the need for polling, which wastes CPU cycles and prevents the processor itself from sleeping and saving power. 

    To configure a run loop, all you have to do is launch your thread, get a reference to the run loop object, install your event handlers, and tell the run loop to run. The infrastructure provided by OS X handles the configuration of the main thread’s run loop for you automatically. If you plan to create long-lived secondary threads, however, you must configure the run loop for those threads yourself.

    Details about run loops and examples of how to use them are provided in Run Loops

    https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Multithreading/AboutThreads/AboutThreads.html#//apple_ref/doc/uid/10000057i-CH6-SW3

  • 相关阅读:
    编程入门之结构体
    编程入门之函数理解
    编程入门之编码风格
    Linux基础 30分钟GDB调试快速突破
    GDB实战
    linux下终端游戏
    DSP学习教程基于28335(一)
    Linux内核模块编程可以使用的内核组件
    Windows10下配置Linux下C语言开发环境
    Git常规配置与基本用法
  • 原文地址:https://www.cnblogs.com/feng9exe/p/8024729.html
Copyright © 2011-2022 走看看