- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
通常,当 main()
退出时,所有线程都会被杀死。 pthread_exit(3)
说
To allow other threads to continue execution, the main thread should terminate by calling pthread_exit() rather than exit(3).
是否有等效的 C++11 API 调用?像 std::this_thread::exit(0)
这样的东西?
最佳答案
Working Draft, Standard for Programming Language C++ 的第 1121 页从 2012-01-16 开始似乎声明一旦主线程退出,它的分离线程也将被清理(除非我误解它):
void detach();
Requires: joinable() is true.
Effects: The thread represented by *this continues execution without the calling thread blocking. When detach() returns, *this no longer represents the possibly continuing thread of execution. When the thread previously represented by *this ends execution, the implementation shall release any owned resources.
Postcondition: get_id() == id().
Throws: system_error when an exception is required (30.2.2).
Error conditions:
— no_such_process — if the thread is not valid.
— invalid_argument — if the thread is not joinable.
关于c++ - C++11 线程是否为分离线程提供了一种在主线程退出后继续运行的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38107707/
有人可以向我澄清主线 DHT 规范中的声明吗? Upon inserting the first node into its routing table and when starting up th
我正在尝试使用 USB 小工具驱动程序使嵌入式设备作为 MTP 设备工作。 我知道 Android 从大容量存储设备切换到 MTP 设备已经有一段时间了,并且找到了 source code for M
我是一名优秀的程序员,十分优秀!