gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 12:14:05 25 4
gpt4 key购买 nike

我想在后台运行一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com