c++ - 使用 std::thread 或 CreateThread()?

标签 c++ multithreading

<分区>

当我开始使用 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/

相关文章:

c# - EF vs SQL 奇怪的慢

Java map 同步

c++ - 哪个 C++ 语言功能在函数调用后重复括号?

c++ - 通用转换运算符模板和 move 语义 : any universal solution?

c++ - Qt 中的 Internet Explorer 窗口?

java - 在Java中运行多线程

C++ std::thread 和方法类

java - Thread.sleep(long) 有多有效?

c++ - 如何使用 UNUSED 宏来消除 CONSTEXPR 函数中的警告?

c++ - 脚本运行后引用 lua 表/对象