文档详情

iOS多线程编程之NSThread的使用.pdf

发布:2021-11-08约1.29万字共9页下载文档
文本预览下载声明
iOS 多线程编程之 NSThread 的使用 分类: iOS 开发进阶 2012-09-23 23:37 39189 人阅读 评论 (18) 收藏 举报 目录(?)[+] 1、简介: 1.1 iOS 有三种多线程编程的技术,分别是: 1. 、NSThread 2 、Cocoa NSOperation (iOS 多线程编程之 NSOperation 和 NSOperationQueue 的使用 ) 3 、GCD 全称: Grand Central Dispatch (iOS 多线程编程之 Grand Central Dispatch(GCD) 介绍 和使用 ) 这三种编程方式从上到下, 抽象度层次是从低到高的, 抽象度越高的使用越简单, 也是 Apple 最推荐使用的。 这篇我们主要介绍和使用 NSThread ,后面会继续 2 、3 的讲解和使用。 1.2 三种方式的有缺点介绍: NSThread: 优点: NSThread 比其他两个轻量级 缺点: 需要自己管理线程的生命周期, 线程同步。 线程同步对数据的加锁会有一定的系统开 销 NSThread 实现的技术有下面三种: Technology Description Cocoa implements threads using the NSThread class. Cocoa also provides methods on NSObject for spawning new threads and Cocoa threads executing code on already-running threads. For more information, see “Using NSThread ” and “Using NSObject to Spawn a Thread. ” 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 POSIX threads 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 is a legacy C-based interface used by applications transitioning from older versions of Mac OS. This technology Multiprocessing is available in OS X only and should be avoided for any new Services development. Instead, you should use the N
显示全部
相似文档