c - 如何在后台运行函数?

标签 c linux multithreading parallel-processing pthreads

我想在后台运行一个 C 函数,但我希望它在 main 时保持运行。函数退出。

我尝试了以下操作:

  1. pthread_detach ,如果main,则分离的线程退出。函数调用exit()而不是pthread_exit .
  2. deamon() :它在后台运行代码,但不是并行运行。

那么,即使在我的 main 之后,并行/后台运行 C 函数的最简单方法是什么?函数退出?

最佳答案

So, what is the simplest way to run a C function in parallel/background even after my main function exits?

通过调用 pthread_exit() 退出 main() .

关于c - 如何在后台运行函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31848424/

相关文章:

linux - 在 linux 中远程运行 history 命令

java - 如何使用处理在单独的线程中读取 OpenGL 像素?

C Signal Handler教授示例讲解

c - 如何将 "bc"的输出存储到变量中?

c - 如何在 makefile 中链接 C 库

linux - 在 openstack 上使用 ansible 实现网络自动化

c - C 中的快速排序 - 只是一个未排序的数字

linux - wait 在此脚本中的表现如何?

multithreading - Gtk#窗口移动在多线程时卡住

java - 为什么线程被称为轻量级进程?