【发布时间】:2014-01-30 13:19:32
【问题描述】:
我对这个小 C 源代码的 pthreads 有疑问:
int calc = 0;
void func(void* data){
calc = 2 * 2;
return NULL;
}
int main(){
pthread_t t;
if(0==pthread_create(&t,NULL,func,NULL)){
if(0==pthread_join(t,NULL)){
printf("Result: %d\n",calc); // 4 ?
}
}
}
如果 pthread_join 返回成功,“func”是否总是完全执行? (在 printf 上 calc 总是等于 4 吗?)。
【问题讨论】:
-
pthread_join的文档是怎么说的? -
函数原型有错别字,应该是void* func(void* data)。