• iOS多线程开发(一)


    线程的相关概念
           1, 线程三状态 ---运行(Running),就绪(Ready),阻塞(Blocked)
           2,   线程入口函数
           3,   Run Loop ---如果需要线程长时间存在, 就需要在线程入口函数内包含一个Run Loop机制
    多线程线相关概念
           4,   线程同步---通过同步工具实现互斥和同步,同步工具包括锁, 条件(信号量),原子操作及其他技术同步资源
           5,  线程间通讯---线程间通讯根据线程的类型有不同的通讯方式
                1)Direct Messaging ---ios中performSelector...方法,包括线程和主线程,线程与线程之间的通讯
                2)Global Variables/Shared memory/Shared Objects ---多线程共同使用他们的进程的内存空间(堆),所以对于全局变量,共享内存和共享对象可以在多线程被使用。但是在处理这些共享内存时,需要注意多线程同步互斥,即对共享资源的同步及互斥,在同一时间只能被一个线程使用。(mutex/condition)
                3)Conditions---Conditions are a synchronization tool that you can use to control when a thread executes a particular portion of code. You can think of conditions as gate keepers, letting a thread run only when the stated condition is met协调控制多线程的执行顺序,这是和Mutex区别之一
                4)Run Loop Sources---处理异步事件的机制之一。A custom run loop source is one that you set up to receive application-specific messages on a thread. Because they are event driven, run loop sources put your thread to sleep automatically when there is nothing to do, which improves your thread’s efficiency.
                5)Ports and Sockets---Port-based communication is a more elaborate way to communication between two threads, but it is also a very reliable technique. More importantly, ports and sockets can be used to communicate with external entities, such as other processes and services. For efficiency, ports are implemented using run loop sources, so your thread sleeps when there is no data waiting on the port.
                6)Message queues---The legacy Multiprocessing Services defines a first-in, first-out (FIFO) queue abstraction for managing incoming and outgoing data. Although message queues are simple and convenient, they are not as efficient as some other communications techniques
                7)Cocoa Distributed Objects---分布式对象处理机制之一。Distributed objects is a Cocoa technology that provides a high-level implementation of port-based communications. Although it is possible to use this technology for inter-thread communication, doing so is highly discouraged because of the amount of overhead it incurs. Distributed objects is much more suitable for communicating with other processes, where the overhead of going between processes is already high
  • 相关阅读:
    SQL Server 2019安装及部署指南
    西门子1200PLC实用定位控制程序案例
    C#进行注册表项和键值操作
    上位机开发必备的一个实体类
    配置Internal Load balancer中VM的外网访问
    从中序后序遍历构造
    网络 | Linux ping任何ip均出现 Destination Host Unreachable 排查思路与方法
    Spring、Spring Framework、Spring Boot、Spring Cloud的区别
    Linux软件安装目录分类讲解
    APP嵌入H5时,软键盘处理(IOS)
  • 原文地址:https://www.cnblogs.com/luqinbin/p/5154198.html
Copyright © 2020-2023  润新知