https://computing.llnl.gov/tutorials/pthreads/samples/join.c
请参阅上面链接中的代码。
问题:
- 线程例程 (
BusyWork) 应该返回 avoid *,但它以调用pthread_exit()( 返回 avoid) 结束。
为什么这没有被标记为失败或错误?我也没有收到任何警告。
https://computing.llnl.gov/tutorials/pthreads/samples/join.c
请参阅上面链接中的代码。
问题:
BusyWork) 应该返回 a void *,但它以调用pthread_exit()( 返回 a void) 结束。为什么这没有被标记为失败或错误?我也没有收到任何警告。
缺失的链接,取自man pthread_create:
在创建时,线程执行 start_routine,并使用 arg 作为其唯一参数。如果 start_routine 返回,效果就像隐式调用 pthread_exit(),使用 start_routine 的返回值作为退出状态。
所以你有两个选择(选择一个):
pthread_exitpthread_exit至于为什么它没有被标记:因为编译器知道pthread_exit永远不会返回。这是如何完成的取决于编译器。在 GCC 上,可以使用__attribute__((__noreturn__)).