pthread : posix thread的簡(jiǎn)稱
導(dǎo)入頭文件
#import <pthread.h>```
###1. 創(chuàng)建線程
```objc
/* 第一個(gè)參數(shù): 線程指針
第二個(gè)參數(shù):線程的屬性
第三個(gè)參數(shù):只想函數(shù)的指針
第四個(gè)參數(shù):函數(shù)的傳值
*/
int pthread_create(pthread_t * __restrict, const pthread_attr_t * __restrict, void *(*)(void *), void * __restrict);
// 使用
void * run(void *param) {
NSLog(@"子線程被調(diào)用了");
return NULL;
}
// 子線程1
pthread_t thread1;
pthread_create(&thread1, NULL, run, NULL);
// 子線程2
pthread_t thread2;
pthread_create(&thread2, NULL, run, NULL);