<分区>
当我开始使用 C/C++ 编写代码时,我正在修改我的代码。
这是关于线程的。在我读过的教程(从 2006 年开始)中,他们说,在为 Windows 开发时,可以使用 CreateThread() 创建线程。使用这个函数比使用 std::thread 更好吗?
它也更快吗?
<分区>
当我开始使用 C/C++ 编写代码时,我正在修改我的代码。
这是关于线程的。在我读过的教程(从 2006 年开始)中,他们说,在为 Windows 开发时,可以使用 CreateThread() 创建线程。使用这个函数比使用 std::thread 更好吗?
它也更快吗?
最佳答案
在加载 CRT 的应用程序中(就像大多数 C/C++ 一样)您不能使用 CreateThread
,按照规范:
A thread in an executable that calls the C run-time library (CRT) should use the
_beginthreadex
and_endthreadex
functions for thread management rather than CreateThread and ExitThread; this requires the use of the multithreaded version of the CRT. If a thread created using CreateThread calls the CRT, the CRT may terminate the process in low-memory conditions.
std::thread
另一方面会做正确的事情。
关于c++ - 使用 std::thread 或 CreateThread()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34820994/