PThread使用方法

来源:互联网 发布:显卡内存多大合适知乎 编辑:程序博客网 时间:2024/06/06 00:24

void *task(void *data) {
//验证传参
printf(“验证传参值:%s”, (char *)data);
//耗时操作
for (int i = 0; i < 20000; i++) {
NSLog(@”执行次数:%d”, i);
}

return NULL;

}

//子线程
- (IBAction)executeTimingOperationByPthread:(id)sender {
//1.创建子线程对象
/*参数一:指定pthread_t类型的子线程地址
参数二:指定线程特定属性(占用内存空间)
参数三:函数声明
参数四:传给上面函数的参数
*/
pthread_t pthread;
char *data = “Hello”;
pthread_create(&pthread, NULL, task, data);
//2.把耗时操作给子线程执行
}

0 0
原创粉丝点击