【问题标题】:Do I need pthread_exit if I don't care of return value如果我不关心返回值,我是否需要 pthread_exit
【发布时间】:2012-12-21 12:18:32
【问题描述】:

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

我想知道在我的数据化 pthread 中不调用 pthread_exit 是否可能存在一些微妙的资源问题。

谢谢。

【问题讨论】:

标签: c++ c pthreads


【解决方案1】:

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

来自manual

   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.

所以,不使用也没关系。

【讨论】:

    【解决方案2】:

    您不必致电pthread_exit()。从线程函数返回也同样有效,并且不会泄漏任何资源(当然,您仍然必须确保您的代码没有任何泄漏)。

    【讨论】:

      猜你喜欢
      • 2013-09-28
      • 2023-03-31
      • 2020-01-17
      • 2021-07-18
      • 1970-01-01
      • 2011-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多