如果我不关心返回值,我需要pthread_exit吗

Do I need pthread_exit if I don't care of return value

本文关键字:pthread exit 不关心 返回值 如果      更新时间:2023-10-16

如果我不关心线程的返回状态,我需要有一个pthread_exit吗?

我想知道是否有一些微妙的资源问题与不调用pthread_exit在我的数据pthreads。

谢谢。

pthread_exit()的目的是如果有其他线程加入,则返回退出代码。

从手册:

   Performing a return from the start function of any thread other than the main
   thread results in an implicit call to pthread_exit(), using the function's
   return value as the thread's exit status.

所以,如果你不使用它也没有什么区别

您不必调用pthread_exit()。从线程函数返回同样可以很好地工作,并且不会泄漏任何资源(当然,您仍然必须确保您的代码没有任何泄漏)。