iOS中实现多线程的技术方案
pthread 实现多线程操作 代码实现: void * run(void *param) { for (NSInteger i = 0; i < 1000; i++) { NSLog(@"---buttonclick---%zd---%@", i, [NSThread currentThread]); } return NULL; } @implementation ViewController - (IBAction)clickButton:(id)sender { // 定义一个线程 pthread_t thread; // 创建一个线程 (参1)pthread_t *restrict:创建线程的指针,(参2)const pthread_attr_t *restrict:线程属性 (参3)void *(*)(void *):线程执行的函数的指针,(参4)void *restrict:null pthread_create(&thread, NULL, run, NULL); // 何时回收线程不需要你考虑 pthread_t thread2; pthread_create(&thread2, NULL, run, NULL); } NSThread实现多线程 一个 NSThread 对象就代表一条线程 创建线程的多种方式 第一种方式:先创建再启动线程 // 创建线程