c - 退出正在执行的 pthread

标签 c pthreads

如何自行终止 pthread 执行?

我有这个代码

while(1)
{
  if(...)
  {
    terminate
  }
  work();
}

我必须使用 pthread_exit(); 但我应该给什么作为参数?

最佳答案

根据手册

The pthread_exit() function terminates the calling thread and returns a value via retval that (if the thread is joinable) is available to another thread in the same process that calls pthread_join(3).

这是您要提供给加入线程的任何值。如果不需要返回值,可以传NULL

关于c - 退出正在执行的 pthread,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36397290/

相关文章:

c - 在 C 中分配内存和生成结构

c++ - 如何在 C++ 中使用 pthread 将数据从一个线程传递到另一个正在运行的线程

c++ - pthread_join 是一个瓶颈

存储出现索引的代码不起作用

c++ - std::thread 可能导致无法使用的堆栈跟踪

php - 共享中央套接字对象的PHP线程

c - 将链表节点传递给 pthread 函数正确

c++ - C 和 C++ 的某些标准之间的差异

c - ECONNRESET 在发送 Linux C

c - 字数统计程序未检测到文本文件中的双新行