无法理解段错误的情况。pthread_join()上的分段错误
int main()
{
int val;
pthread_t thread;
...........................
pthread_join(thread,(void **) &val);
printf("Val=%d",val);
//and here sometimes come segmentation
//fault and other times i get correct val value
...........................
}
void *Do(void *)
{
int retval=4;
...............
pthread_exit((void *) retval);
}
如果我正确,了pthread_exit()存储ADDRES(其值为4)到由(& VAL)指针,这意味着VAL = 4在pthread_join后()指出变量。但是,如果我多次启动程序,就会得到正确的val值(即4)和不同启动时的分段错误。 (顺便说一句,在Do函数中使用指针和动态分配的正确方式时,结果相同)。
请帮助我。 预先感谢您。
你拿出太多了。在添加更多内容时,请修复缩进。 – Wug 2012-07-26 18:42:38