一:pthread_create 进程创建
void*t1(void* v){
}
int n=1;
pthread_t tid1;
int* niters=&n;
pthread_create(&tid1, NULL, t1, (void*) niters);
&tid1----进程号地址
t1–线程所指函数名,注意 t1 的返回值由 pthread_create 参数表规定了是 void*
(void*)niters----向 t1 传递的参数
规定是void* 型的指针
这里可以把 int* 强制转化成 void* 传递过去,也就实现了int的传参
二:pthread_join 等待进程结束
void* p=NULL;
pthread_join(tid1,&p);
sum_p+=*(int*)p;
tid1 ----进程号
&p—参数表要求这里是 void** 类型,所以在 void* p 前加一个&
指针p接收线程函数 void* 型的返回值
如果想返回 int 型的值,则对void* 做int* 的强制转化,然后*访问