c++ - c++11线程平台独立吗?

标签 c++ multithreading c++11

我找了很多问题和答案,但我真的想不通这个问题。昨天我在 Visual C++ 项目中尝试了 Windows 上的 C++11 线程,它工作正常。

这是否意味着我们可以在每个具有支持 C++11 的编译器的平台上使用 C++11 线程?有什么理由不使用此线程而不是 pthread 或 Windows 线程(取决于平台)?

最佳答案

C++ 11 线程库仍然使用来自操作系统的线程并依赖于它们,但它以一种很好的方式进行了抽象,因此您几乎不会体验到任何差异。行为仅在细节上有所不同,您几乎不会注意到它们(仅在边缘情况和/或失败时)。可能仍然有一些平台不支持 std::thread 中的所有内容(即使在 2015 年,例如在某些特定/异国情调的移动平台上)。

来自 C++ 标准:

30 Thread support library

Some functions described in this Clause are specified to throw exceptions of type system_error (19.5.6). Such exceptions shall be thrown if any of the function’s error conditions is detected or a call to an operating system or other underlying API results in an error that prevents the library function from meeting its specifications. Failure to allocate storage shall be reported as described in 17.6.5.12.

关于c++ - c++11线程平台独立吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32659072/

相关文章:

c++ - Qt 5.7 将 -std=gnu++11 添加到我的编译器标志,破坏 -std=c++14

c++ - std::string 的生命周期作为参数传递

c# - GDI+ 图像比 C# 图像快得多

c++ - 从展平的 3D 数组计算 3D 坐标

c# - WaitHandle.WaitAny 和信号量类

c++ - 在线程内调用纯虚方法

C++11 线程段错误

c++ - 如何将值插入结构中的 vector

java - 仅具有局部变量的实例方法的线程安全

python - 执行python脚本时,脚本在线程上阻塞,但不在交互模式下