Chinaunix首页 | 论坛 | 博客
  • 博客访问: 639641
  • 博文数量: 133
  • 博客积分: 1566
  • 博客等级: 上尉
  • 技术积分: 1230
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-01 09:31
文章分类

全部博文(133)

文章存档

2019年(1)

2018年(1)

2017年(8)

2016年(9)

2015年(17)

2014年(4)

2013年(31)

2012年(25)

2011年(36)

2010年(1)

我的朋友

分类: 系统运维

2012-11-12 20:07:14


线程的相关概念
       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---处理异步事件的机制之一。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

 

 

 

 

      
阅读(8347) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~