线程支持-外军电台手册

时间:2021-06-07 22:47:16
【文件属性】:
文件名称:线程支持-外军电台手册
文件大小:1.39MB
文件格式:PDF
更新时间:2021-06-07 22:47:16
objective-c ios 1.4 线程支持 如果你已经有代码使用了多线程,Mac OS X和 iOS提供几种技术来在你的应用程 序里面创建多线程。此外,两个系统都提供了管理和同步你需要在这些线程里面处理 的工作。以下几个部分描述了一些你在 Mac OS X 和 iOS 上面使用多线程的时候需要 注意的关键技术。 1.4.1 线程包 虽然多线程的底层实现机制是 Mach的线程,你很少(即使有)使用 Mach级的线 程。相反,你会经常使用到更多易用的 POSIX 的 API 或者它的衍生工具。Mach 的实 现没有提供多线程的基本特征,但是包括抢占式的执行模型和调度线程的能力,所以 它们是相互独立的。 列表 1-2列举你可以在你的应用程序使用的线程技术。 Table 1-2 Thread technologies Technology Description Cocoa threads Cocoa implements threads using the NSThread class. Cocoa also provides methods on NSObject for spawning new threads and executing code on already-running threads. For more information, see “Using NSThread” and “Using NSObject to Spawn a Thread.” POSIX threads POSIX threads provide a C-based interface for creating threads. If you are not writing a Cocoa application, this is the best choice for creating threads. The POSIX interface is relatively simple to use and offers ample flexibility for configuring your threads. For more information, see “Using POSIX Threads” Multiprocessing Services Multiprocessing Services is a legacy C-based interface used by applications transitioning from older versions of Mac OS. This technology is available in Mac OS X only and should be avoided for any new development. Instead, you should use the NSThread class or POSIX threads. If you need more information on this technology, see Multiprocessing Services Programming Guide. 在应用层上,其他平台一样所有线程的行为本质上是相同的。线程启动之后,线 程就进入三个状态中的任何一个:运行(running)、就绪(ready)、阻塞(blocked)。如 果一个线程当前没有运行,那么它不是处于阻塞,就是等待外部输入,或者已经准备 就绪等待分配 CPU。线程持续在这三个状态之间切换,直到它最终退出或者进入中断 状态。 当你创建一个新的线程,你必须指定该线程的入口点函数(或 Cocoa线程时候为 入口点方法)。该入口点函数由你想要在该线程上面执行的代码组成。但函数返回的

网友评论