Nig*_*ain 6 c join return pthreads
我正在尝试从pthread_join打印返回值.我有以下代码:
for(j = 0 ; j < i ; ++j){
pthread_join( tid[j], returnValue); /* BLOCK */
printf("%d\n", (int)&&returnValue);
}
Run Code Online (Sandbox Code Playgroud)
所有线程都存储在tid数组中,并且可以正确创建和返回.在每个线程函数结束时,我有以下行:
pthread_exit((void *)buf.st_size);
Run Code Online (Sandbox Code Playgroud)
我试图返回我正在阅读的文件的大小.由于某种原因,我不能让它打印正确的值.这可能是我试图从pthread_join函数调用中取消引用void**的方式,但我不太清楚如何去做.在此先感谢您的帮助.
Chr*_*odd 10
您需要将void *变量的地址传递给pthread_join- 它将使用退出值填充:
for(j = 0 ; j < i ; ++j) {
void *returnValue;
pthread_join( tid[j], &returnValue); /* BLOCK */
printf("%d\n", (int)returnValue);
}
Run Code Online (Sandbox Code Playgroud)